Move Object in the direction of its local position.

Hello, everyone!

I am stuck in this situation where I want my game object (Hoops) to move up and down relative to its rotation. For example, if hoops are at rotation let’s say, X:90, Y:90, Z:0, they are horizontal to the plane so if I use Mathf.Sin(Time.deltaTime * _speed) they work fine, they go up and down. but they only go up and down as not all of the hoops will be at those mentioned rotations some will be tilted (to have difficulty in the game).

so, I seek help regarding this situation as to how to move those randomly tilted hoops relative to their rotation.
so, if X: 65, Y: 90, Z:0, they move according to their local position and not just go up and down.

I’m sure there has to be an easy solution for this. :slight_smile:

The correct solution depends on your code but what you are looking for is gameObject.transform.forward which will always give you the forward direction of your objects, no matter how they are rotated.

Thank you for the reply. My apologies if my question caused some confusion or wasn’t straight to the point.
i hope these images may explain them further.

So i actually want these hoops to move in their LOCAL position instead of GLOBAL which is always the same.

These hoops rotate to some degrees randomly hence their local position changes.

I wish to move them along their local Z-Axis as that will move them “Up and Down”.

I saw one post where they used transform.TranformDirection(); .This works along with the Mathf.Sin(Time.time). but the weird problem is that it should then move the hoops from -1 to 1 but it does so without starting from 0 and if I use Mathf.Sin(Time. time) directly as my hoops Y-Position, then it moves it as per its GLOBAL position.

I hope i could explain myself this time :slight_smile:6908417--809282--global.PNG.jpg 6908417--809285--local.PNG.jpg