Since 4.3 came out I decided I would make a simple top down game, but when I try to make the character rotate to face the mouse it just flips out. Could someone give me a quick rundown on how to do this with a 2D sprite?
1 Answer
1I do this:
var pos : Vector3;
pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
pos.z = 0;
var angle = Vector3.Angle(pos-transform.position,Vector3.down);
if(pos.x > transform.position.x)
angle*=-1;
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0,0,180-angle),rotateSpeed*Time.deltaTime);
–Fixed the code.
Hey this works, thanks. Just a few questions. What do you have rotateSpeed set to? with the rotateSpeed at 20 the character rotation is jumpy and I'm not sure why that is. Just wondering if there's a way to fix that.
– OverxIs it across the X and Y axis? I made it to test new Sprite system.
– CanCo