I have a space ship in a 2D top down game. Ive been messing around with a script from the unity answers. Here is the script:
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour
{
public float speed = 1.5f;
private Vector3 target;
public Camera PlayerCamera;
void Start()
{
target = transform.position;
}
void Update()
{
if (Input.GetKey(KeyCode.Mouse0))
{
target = PlayerCamera.ScreenToWorldPoint(Input.mousePosition);
target.y = transform.position.y;
target = new Vector3(target.y, transform.position.x, target.z);
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
//transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}
when I click the mouse0 button my player moves a little to the left and stops. I do not know why this is.
At the moment I am just trying to get it to follow the mouse but eventually the player will rotate to go a different direction when the mouse position is changed.
Thank you for your help!
↧