- Home /
Question by
theawesome1 · Dec 04, 2020 at 06:32 PM ·
rotationmovementrotaterotate objectforward
gameobject stops moving correctly when rotating
when my gameobject rotates and moves forward, it moves left and then right in leke a swaying motion instead of moving forward and rotating. here is the code:
public float rotationspeed;
public float speed;
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
transform.Rotate(0, 0, 50 * rotationspeed * Time.deltaTime);
transform.Translate(Vector2.right * speed * Time.deltaTime);
}`
Comment
Best Answer
Answer by theawesome1 · Dec 05, 2020 at 03:39 AM
someone on Reddit called Krcko98 told me this as the answer: Use a parent for your object and move the parent but rotate the child object. You cannot do both at the same time since you are using the direction of the transform and that depends on the object's orientation in space directly affected by rotation.