Help rotating along a GameObject

Hi guys, I’m trying to figure out a simple algorithm but I can’t find any solution, so any help will be appreciated :slight_smile:

So here is my problem. I have a GameObject that follows my player but I want the GameObject to always be on the right side of my player no matter the rotation of it. So I want my GameObject to follow the orientation of my GameObject not word relative.

So for example here is what my current script is achieving

And here is a picture of what is happening with my script

And here’s what I need

When I rotate the player I need the GameObject to go to the new _destination and face the same place as the player. Ps : the 10f means the distance between the player and the GameObject.

I have a current script which is part of my Mobs AI.

 transform.rotation = playerTarget.transform.rotation;
                _destination = new Vector3(transform.position.x, transform.position.y, playerTarget.transform.position.z); // this give me the rotation along the world orientation
                transform.position = Vector3.MoveTowards(transform.position, _destination,0.3f);

Thanks you very much :slight_smile:

How about a emptyObject child on your player,
and then just tell your following object, to head towards the emptyObject,

if your player turns right, the object will do exactly what you do (be carefull becouse of collision)

1 Like

Not a bad idea ! If I can’t find a way to do this without an emptyObject I will do this Thanks :slight_smile:

1 Like

Terraya’s idea scales the best, for in the future you might want two minions to follow you, so you want them to take up kind of a “formation” around you.

But if you desperately want to just NOT use the empty object, you can always use the transform shortcuts for your character and compute the offset in realtime from there. For example:

Vector3 OnMyLeftOneStepBehind = transform.position +
    transform.right * -3.0f + transform.forward * -2.0f;

Regardless of which way you face, that will always be 3 units to your left and 2 units behind you… handy!

2 Likes