Hey folks, I have been bashing my head on this for a week now trying out all kinds of different methods and I feel like this should be easier than I’m making it. However nothing I have tried thus far works.
I am making a top down sprite character that moves exactly with the mouse cursor. This part works just fine, but I also want it to face the direction it is moving in but I just cannot get it to rotate on the Z axis so that it remains flat to the camera but rotates around to face its movement direction.
I’ve been trawling through various topics here, on youtube, stackoverflow, I am at a loss and its driving me nuts that I feel it should be a really simple thing to achieve but it just doesn’t seem to be a done thing. a lot of the “follow cursor” methods require the object to follow the direction of the cursor, not be exactly on the cursors position, which, isn’t what I’m aiming at. I want it to be exactly at the point of the cursor.
Here’s my code, what rotation to direction of travel method using this cursor movement method would you recommend here?
{
private Vector3 pos;
void Awake()
{
//Cursor.visible = false;
}
void Update()
{
pos = Input.mousePosition;
pos.z = 980f; //positions at Z =0 from the camera, camera is at -980 Z.
Debug.Log("pos.x");
Debug.Log("pos.y");
}
private void FixedUpdate()
{
transform.position = Camera.main.ScreenToWorldPoint(pos);
}
}