- Home /
rolling ball is a child that needs to be steered by parent
Hi, I'm making a virtual art installation In which I have a rolling ball which moves with mouse input. With this script:
function Update () { transform.position.x -= (Input.GetAxis("Mouse X") 0.08); transform.position.z += (Input.GetAxis("Mouse Y") 0.08); }
This makes the ball roll in X & Z directions just fine. Now I want to be able to steer it. So I made an empty gameObject as parent and attached this script to it:
function Update () { transform.rotation.y -= (Input.GetAxis("Mouse X") * 0.01); }
Now when the mouse moves over the X-axis the ball should slightly steer to the right or the left. But this isn't working. The parent rotates but the child doesn't get the same direction. So it keeps rolling in the same x & z directions ignoring the direction the parent is facing.
When the ball moves physics make it rotate, so when i use anything with rotation I get undesired effects.
Is my question clear enough? Who can push me in the right direction?
Thanks in advance.
Answer by sneftel · May 27, 2011 at 02:51 PM
Parenting the object isn't going to have a significant impact on the physics. To gently steer a ball, apply a force on it in the direction you want it to go. (Remember to do this in FixedUpdate -- you shouldn't affect physics in Update.)
Your answer
Follow this Question
Related Questions
Create a "free" rolling ball controlled by player 1 Answer
How to roll a ball with moving platform. 1 Answer
Ball rolling on platform 0 Answers
moving and jumping ball using physics 2 Answers
How to make a ball that can roll? 2 Answers