- Home /
Character Controller falls when over Moving Platform
I know that there's a lot of questions about this topic in the forum but none of them actually helped my. Besides, there's a lot of posts saying to look the 2D tutorial but it seems unable now...
The question is: I have a character controller with a BoxCollider (triggered) and I want to make it stay over a floating platform while moving. The platform is a kinnematic rigidbody.
I've already tried to use OnControllerColliderHit to recieve the speed from the platform and apply it to the player but then my character seems not to move at the same time as the platform. Also I've tried parenting player's translate with platform's translate (using OnTriggerStay) but I wasn't able to do this too.
Can anyone halp me with this problem?
Answer by FL · Feb 06, 2013 at 12:05 AM
I also had problems with this, but finally manage to make a moving platform and an elevator working.
You can't do this with a Trigger (only if you have a bigger platform collider as trigger and a child object with actual platform). If you don't use Trigger, have both (platform and player) with rigidbodies and colliders.
Disable platform gravity. Make sure that OnCollisionEnter or OnTriggerEnter are called in contact.
Creates a private empty array. In Start(), put this object in this array. In OnCollisionEnter/OnTriggerEnter add every collision/collider object that have a character controller and/or rigidbody to this array. In OnCollisionExit/OnTriggerExit, remove the object in collision/collider of the array. In Update (I recommend FixedUpdate), for every object in this array, call the line object.transform.position += distanceVectorPerUpdate
, this variable can be something like Vector3(0,0,1)
.
Your answer
Follow this Question
Related Questions
How to get a character to stay on a moving platform? 3 Answers
Can´t get the character to Stay on a moving Platform 1 Answer
Why is this happening? (gif attached) 2 Answers
Character Controller and Moving Rigid Bidy 0 Answers
How to Instantiate objects randomly within the space of another moving object? 1 Answer