So, forgive me 100% if Google failed to bring up the result I needed, but I’ve been hunting for a bit.
Now, I know… the whole “empty game object” trick to set your own new pivot… that’s not what I’m working on.
What I would like to do is rotate one game object based on the pivot point of ANOTHER game object. In other words, I want to dynamically move the pivot point to the position of the player, but not rotate the player… rotate the platform the player is on.
Currently, I have the rotating working, but the further away from the center of the object, the harder it is to control the player object. The fix is to pivot at the point of the player, but not pivoting the player.
Any ideas where I should start? (Yes, I’ve done a few tutorials, I’m asking for direct help on this specific logic)
Thanks in advance.
Transform.RotateAround:
rotates the transform around some axis at some point by degrees in world space.
1 Like
Thanks lordofduct, I’m going to try this right now and I’ll let you know if it works. From the documentation it seems to be exactly what I’m looking for… and I feel silly for not looking more into this when I found it in the API docs.
EDIT: Okay, so that worked, but it is using different logic and required extra coding to regain my function I originally had. Let me explain.
I was using
transform.rotation = QuaternionEuler (Input.GetAxis(“Horizontal”), 0.0f, Input.GetAxis(“Vertical”));
to rotate, and this would set the rotated object back to zero when axis was released.
With RotateAround, I gave it the position of another object (works as intended), the direction it will go (I used the axes Vertical/Horizontal in Input manager), and the angle/time? Either way, that part works as well… but it does not return the object back to zero when the axes are released.
I had to add a few if statements checking if an axis was down, and if the planes rotation was greater/less than zero, and then adjust accordingly… is there an easier way to do that? I can share the code if it sounds too complicated, but it’s on my other computer and I was just curious.