- Home /
I need an object to rotate using a moving object as a pivot.
What I have is a marble maze base game, where the floor tilts and the ball rolls around. What I would like would be to have the floor, instead of tilting around the origin, have it tilt around the moving ball.(like super monkey ball does) That way the ball wouldn't bounce around and level sizes wouldn't be limited.
I've tried multiple ways, but I'm currently trying to use transform.RotateAround to use the ball as a guide.(not actually the ball, but an emptyGameObject parent of it so it isn't affected by the rolling) RotateAround doesn't seem to do what I want, but it's the only thing I can find where I can change the point around which the floor rotates.
public class WorldTiltTest : MonoBehaviour
{
public float speed;
public float max;
public GameObject player;
void FixedUpdate()
{
//Player Input
float step = speed * Time.deltaTime;
float tiltX = -Input.GetAxis ("Horizontal") + Input.GetAxis ("Vertical");
float tiltZ = Input.GetAxis ("Horizontal") + Input.GetAxis ("Vertical");
Vector3 PlayerPossition = player.transform.position;
Quaternion Rotator = Quaternion.RotateTowards (transform.rotation, Quaternion.Euler(max * tiltZ, 0, max * tiltX), step);
transform.RotateAround (PlayerPossition,
Rotator.eulerAngles,
*not sure what to put here. 0 doesn't work and any number just makes it constantly spin*);
}
}
This is the code I'm using that actually does its job, though it only rotates around origin.
public class WorldTilt : MonoBehaviour
{
public float speed;
public float max;
void FixedUpdate()
{
//Player Input
float step = speed * Time.deltaTime;
float tiltX = -Input.GetAxis ("Horizontal") + Input.GetAxis ("Vertical");
float tiltZ = Input.GetAxis ("Horizontal") + Input.GetAxis ("Vertical");
rigidbody.rotation = Quaternion.RotateTowards (transform.rotation, Quaternion.Euler(max * tiltZ, 0, max * tiltX), step);
}
}
Hi, check out this other user's thread for your transform.RotateAround solution: http://answers.unity3d.com/questions/323032/how-to-rotate-one-object-around-another-one.html
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Quaternions acting up 1 Answer
Position and rotate 3 sprites perpendicular to the edges of a triangle 1 Answer
Why is this rotation acting odd? 0 Answers