- Home /
Creating a 3D orbital movement
I am trying to make 2 different player controlled character move around a central axis in 3D space.
I have used the following method of making the orbiting object a child of an object at 0,0,0
float rotationX = Input.GetAxis("Vertical");
float rotationY = Input.GetAxis("Horizontal");
rotationX *= Time.deltaTime;
rotationY *= Time.deltaTime;
transform.Rotate(rotationX, 0, 0);
transform.Rotate(0, -rotationY, 0);
This works, but is feeling rather clumsy and makes it difficult to apply other changes I need to the orbiting object.
I have tried using rotatearound but this does not provide a suitable solution as far as I can take it, as once the object has rotated 90 degrees in one direction the other rotation no longer creates an orbit but rather the objects just spins in place.
Any help would be appreciated.
You can use cylinder coordinates ins$$anonymous$$d of cartesian ones. Interpolate these coordinates and transform them into cartesian ones to get the correct position in 3D-space. You will need to do some maths though.
What are the other changes you need?
When using RotateAround, if you also rotate the object in place at the same time, you can then try using its local transform.up and transform.right in making the other rotation.