- Home /
Character Controller and moving/lerping object collisions
Seems simple enough. In this scenario, there are several moving platforms that lerp back and forth.
When one of these platforms hits the player (character controller), it should push the player along with it, instead of moving through the player.
The problem is that if the player isn't moving (is standing still), OnControllerColliderHit is never called. Attaching Rigidbodies to the moving objects does not call OnCollisionEnter properly in this circumstance either.
Currently, I am working around the issue by raycasting to the right and the left every frame. If there is a hit and the hit object is moving, the player will make itself a child of the moving object - giving the illusion that the player is being pushed.
This works fine, but when I want the player to run faster, the effect is hit or miss. Aside from that, the constant raycasting is a bit messy and feels somewhat hacky.
Is there a cleaner, more efficient, more reliable way of determining collisions between a Character Controller and a moving/lerping object?
Did you try OnCollisionEnter on the platform or the character? I'm pretty new to Unity, but I think both should work.
Are the moving objects set as kinematic? (Shouldn't be the biggest issue, but might help.)
You can try setting the RigidBodies check from discrete to continuous if it's missing the object in-between frames. Though that is more computationally expensive.
Roy:
I have tried OnCollisionEnter on both the platforms and on the character.
I have added a RigidBody to the player, which also uses a Character Controller. is$$anonymous$$inematic is true for each.
I have set the collision check to both continuous and dynamic continuous.
However, OnCollisionEnter is not getting called on either the player or the platform.
Its hard to tell what the problem is. Are you sure that the colliders are NOT set as trigger? See: http://forum.unity3d.com/threads/23126-Character-OnCollisionEnter And http://answers.unity3d.com/questions/210220/apparently-i-dont-understand-oncollisionenter.html
Your answer
Follow this Question
Related Questions
Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer
Character Controller meets Rigidbody 1 Answer
Problem with character controller and collisions 1 Answer
Collision CharacterController vs CharacterController 2 Answers
NPCs fall through hills in terrain 1 Answer