Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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: docs.unity3d.com/ScriptReference/Transform.Translate.html.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading