- Home /
Rigidbody on a platform
Hey!
I know the question is already asked here , but the answer is not clear
I want to make my rigidbody objects moving with the platforms ? How can I do that , i've tried checking use Kinematic on the platform , the rigidbody stays better on the platform but it slips quickly though even when the motion of the platform is very slow.
Thank you for reading.
parent your rigidbody temporarily to the plattform, when he enters it
Try applying physics materials to the platform and the rigidbody
I've tried that
function OnCollisionStay (TheCollision : Collision) { if(TheCollision.gameObject.tag == "Plateform"){ Debug.Log("NNNNNNNOOOOOOOOOO"); transform.parent = TheCollision.transform ; } }
it works , but I don't know how to separate it from the platform when the cube is out of it, i've tried transform.parent = null; and transform.DetachChildren(); but neither work :(
Answer by FLASHDENMARK · Sep 18, 2011 at 11:22 AM
function OnCollisionStay (hit : Collision) {
if(hit.gameObject.tag == "Plateform"){
transform.parent = hit.transform ;
}else{
transform.parent = null;
}
That should add you as a child under the platform and it should separate you from the platform when you are no longer on it.
You mean transform.parent = hit.transform; right? ;)
Is there anyway to change the parent so it only follows its position. because my object scales as well as moves with the object. I think the problem is because my platform is animated. so i only want to parent its position.
The problem is most likely not that your platform is animated, but that your platform (or perhaps also character, don't know) is non-uniformly scaled. It is a know problem. The guys behind Unity also explains it here:
http://docs.unity3d.com/Documentation/Components/class-Transform.html
Under "Performance Issues and Limitations with Non-Uniform Scaling"
You should scale your platform (perhaps also character) so that their X, Y and Z values are uniform e.g (3, 3 ,3) or alike.
Thank you. Ive gotten it to work. Also, is there a way to make the parenting more accurate. beacause when i am in the air. It still seems to be parented to it so sometimes when its moving away from me. and i jumpoff in the opposite direction. its give me a pull towards it.
Answer by hannesdvl · Mar 08, 2013 at 05:12 PM
Moving using only Rigidbody.MovePosition and Rigidbody.MoveRotation in FixedUpdate fixes the slipping and gives a very smooth and accurate simulation.
From the docs: http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.MovePosition.html
For kinematic rigidbodies it applies friction based on the motion of the rigidbody. This lets you simulate moving platforms with rigidbodies sitting on top of the elevator. If you want other rigidbodies to interact with the kinematic rigidbody you need to move it in the FixedUpdate function.
This worked perfectly in a 2.5D platformer I am developing with a rigidbody based character. I did have to set Is$$anonymous$$inematic=true on the platform' rigidbody or objects would fall through the elevator platform.
hannesdvl — Thank you so much for the correct answer.
I've been looking for this for a long time.
It's exactly as simple as you said, and as the unity page says which you linked to.
That page also has other useful information on it.
The platform has to be a $$anonymous$$inematic body and it moves characters that are on it.
It's genius!!! Far more efficient than the silly parent-child temp fix. LoL
Works a whole lot better. Thank you so much!!!
When I follow the example in the unity page my platform teleports to the location. I'm looking for a back and forth motion and my FixedUpdate script looks like this. void FixedUpdate () { if(rgb2d.position == (Vector2)wayPointA.position) destination = wayPointB.position; else if(rgb2d.position == (Vector2)wayPointB.position) destination = wayPointA.position; rgb2d.$$anonymous$$ovePosition(destination + velocity * Time.fixedDeltaTime); }
velocity is set to new Vector(1.0f, 0);
What am I doing wrong and how did you get yours to work? Thank you.
You don't want to move the object by destination, only by the velocity you desire.
Your answer
Follow this Question
Related Questions
Something on a moving platform 2 Answers
Parenting a player to a rigidbody platform 0 Answers
Prevent Player to push Rigidbody 0 Answers
movement inside a train problem 1 Answer
GameObject pivot vs center 1 Answer