- Home /
Making a ball stay on the ground unless jumping?
I am making this ball and platform game and I have added some moving platforms that move vertically (up and down) but when the platform goes down, the ball stays in the air and starts to fall down to the platform. How can I fix this?
Answer by AeonIxion · Nov 20, 2013 at 11:54 PM
I believe this is similar to the problem I was facing a while ago. What I did: create an empty game object and make it a child of your platform. Add a box collider to the empty game object and set it as trigger. Make sure the trigger is a bit bigger than the collider on your platform.
Add a script to your ball with the following code:
void OnTriggerEnter(Collider col)
{
gameObject.transform.parent = col.transform.root;
}
void OnTriggerExit(Collider col)
{
gameObject.transform.parent = null;
}
Your answer
Follow this Question
Related Questions
how to find rigid bodies rested in ground? 0 Answers
Place On Ground 1 Answer
Keep an object on the gound. 2 Answers
OnTriggerStay not working properly 2 Answers