- Home /
how to make an object move like the one it is in contact(moving using Animator) with in unity?
I am new to unity. I am currently trying to create a basic 3 D game in which a game object is needed to jump on a moving platform and move along with it until i use my controls to move it like usual. I used an Animator to move the platform back and forth between 2 points. I had Rigid body on the game object and Mesh Collider on the platform.
When i play it now the game object falls on the platform but if does not move along with the platform but it stays in the same position from where it falls on the platform until the platform moves away and then it falls down. How to make it move along with the platform when it in Contact with it? I hope this is understandable
Answer by highpockets · Jun 02, 2019 at 08:22 AM
Make the player a child of the platform when he is grounded on it and remove the parent when he is not on the platform. I would put a rigidbody on the platform as well and turn it to kinematic.
//when in contact with the platform
player.transform.parent = platform.transform;
And when the player gets off the platform:
player.transform.parent = null;
Your answer
Follow this Question
Related Questions
Find Quadratic Equation From 3 points for Jump 1 Answer
Simultaneously moving GameObjects using C# script. 3 Answers
Advance seesaw effect 0 Answers
Check if 2 objects positions are close enough 2 Answers
Bullets spawn behind plane? 1 Answer