- Home /
How to maintain collision while moving the player?
Well it's a basic problem: When moving a platform (Player is grounded on it) the camera first starts shaking and then when the speed is raised (platform moves vertically up and down with raising speed) the player simply falls trough the platform following the rules of gravity.
Question is: How can I prevent that from happening?
Hmm, is your platform a plane? I read somewhere (can't find the link unfortunately) that physics doesn't really work very well on plane colliders because the collision sampling intervals won't actually detect the plane colliders and completely bypass it ... or something like that. Can't really remember ...
$$anonymous$$y basic question is: are you using a plane for your platform? If so, try using a very thin cube for your platform and see if that helps in any way.
Thanks for your hint, I am using a thick cube as my moving platform. Nevertheless the player falls through it whenever the cube moves faster than a certain rate (like 5-10 units per second).
Why are you moving the platform? I am not getting this question. Can you please elucidate?
Answer by venkspower · Apr 23, 2012 at 12:05 PM
Alright. Make the Platform (or Plane, or whatever you have given) as the parent for the Character Controller like
CharacterController.transform.parent = Platform.transform
And do the animation for the Platform gameObject. I think, that would make it right.
And apply the colliders to the Platform gameObject, if you haven't!
Answer by aldonaletto · Apr 23, 2012 at 11:34 AM
This is a recurrent problem with the CharacterController: I suspect it only checks collision when Move or SimpleMove are used; if you don't move the character with these instructions while the platform is moving, the character can miss the movement and simply find himself a little below the platform surface, what makes him fall. A dirty hack usually solves this problem: slightly move the character horizontally each Update - something like this:
function Update(){
GetComponent(CharacterController).Move(Vector3.forward * 0.01 * Time.deltaTime);
}
You can add this code to an existing character script, or create a new one.
Thanks for your help! I tried your solution, unfortunately the problem still exists... $$anonymous$$aybe I should lock the players movement and move the character controller itself once it collides with the platform?