GameObjects go in different directions Unity

This is the most important part of the script:

    void Update()
        transform.Translate(Vector2.right * speed * Time.deltaTime);

This is suppose to make my gameobject go in the right direction but if I am rotating the gameobject 180*, right becomes left, how can I make it so right remains right.

I Created an empty gameobject called "Obstacle" object where I store 2 of those objects called "hand"
So I have 2child objects called hand in the parent Obstacle, I want right to be right for all of them no matter if they are rotated or anything.

I also want to animate them, I did a test and animating the objects won’t move them anymore’ at all.

It initialise the object but it is not moving.

>Solution :

Answering the first part of your question:

transform.translate acts in the relative space of the object and is aligned with its own axes, not with the world. So, if you rotate the object, Vector.right will return the right direction in that precise reference frame. If you want the object to always move right, independent on their orientation, you might want to try something like transform.Translate(Vector2.right * speed * Time.deltaTime, Space.World); instead as described here in the official documentation:

Leave a Reply