Question by
0x1 · Jun 08, 2016 at 03:18 AM ·
top down shootertop down
Top down rotation and translate 2d
Hi, i hope someone can help me with this, i'm very noob and trying to learn. I have the next code trying to get working rotation and movement, but something it's wrong. The sprite can't move to the left, right works, if i try to move it up or down it goes slightly to the left, if i remove the code for the rotation it can move without rotation, what i'm doing bad? what can i do to make it work with rotation and movement? Thank's in advance.
Vector3 valorInput;
valorInput.z = 0;
valorInput.y = CrossPlatformInputManager.GetAxis("Vertical");
valorInput.x = CrossPlatformInputManager.GetAxis("Horizontal");
if (valorInput.x != 0 || valorInput.y != 0){
float angle = Mathf.Atan2(valorInput.y, valorInput.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.AngleAxis(angle, Vector3.forward), Time.deltaTime * 30);
}
transform.Translate(valorInput * Time.deltaTime );
Comment