Question by
RaytjeKnOfficial · Apr 12, 2017 at 06:11 PM ·
2dmovementphysics2d
When using transform.Translate and Rotate It moves weared.
First of all, sorry for my bad English. Second I'm in 2d. I'm making a game, when I press 'a' it goes to left and rotates a bit to the left and clockwise with 'd'.
public class SpermMovement : MonoBehaviour {
private Rigidbody2D rb;
private float speed;
private bool Rotate;
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
speed = FindObjectOfType<GameManager>().speed;
}
void Update () {
//Debug.Log();
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
if (Input.GetAxis("Horizontal") > 0)
{
transform.eulerAngles = new Vector3(0, 0, -10f);
} else if (Input.GetAxis("Horizontal") < 0)
{
transform.eulerAngles = new Vector3(0, 0, 10f);
}
transform.Translate((Vector2.right * speed * Time.deltaTime) * h);
if (h == 0)
{
transform.eulerAngles = new Vector3(0, 0, 0);
}
}
private void OnCollisionEnter2D()
{
Debug.Log("DEAD!");
}
}
When I am using this the character will move in the -y direction when I'm rotating. This is a little animation: link text. I also froze the position on the y axis, but this won't do anything as of transform.Translate doesn't think of physics. How do I fix this? Any solutions?
Comment