- Home /
How to prevent Character Controller from sliding during riding an animated platform?
Hello guys,
in my game I have a train which the player is supposed to ride in order to get from one station to the next one. I put a locomotion and several waggons as child objects to one empty game object which I animated within Unity, using the legacy system, to move between the stations. The player is able to enter the locomotion and should be able to move around within the vehicle. However, when the train moves the character controller is first sliding against the movement direction and then back agains towards the moving direction. In the end, when arriving at the second station, the player is back at his original place. Not sure if it's really sliding or if the player is simply moving slower than the train in the first part of the ride respectively faster in during the second one. The train elements all have colliders attached and no other components. I haven't added any components to the Character Controller. Also, when the player jumps he falls off or through the train onto the track. Disabling the sliding property on the Character Controller didn't have any impact on the issue. I have similar problems with an elevator. I assumed moving platform support to be included and working more or less on its own without having to manually tweak things and I can't really figure a way to make it work. I also tried parenting the locomotion to the player for the time of the ride but when doing so the Controller is kind of forced to a position and not able to move until the animation has finished. I hope you guys can help me with this issue. Do I have to add some components (rigidbodys?)? I know there are several posts on moving platform stuff around but I didn't have any success with these. Many thanks in advance!
Answer by ddmx · Feb 23, 2013 at 06:48 PM
You'll need to make sure that the character's velocity profile is computed as relative to the object he's standing on. When he's on a stationary platform it's easy. When the platform is moving his zero velocity now becomes that of the platforms. Anything on top of that like movement for instance is now charVel+=trainVel
Hope that helps.
But shouldn't that already be included out of the box within the character motor script of the standard character controller? I looked at the script and there is already code there that takes care of adding the velocity of a moving platform to the controller's own velocity.
I think that you still have to assign the platform variable of the controller using another script for the out-of-the-box script to work(or you can extend the ready-made script, whichever way that floats your boat). Last time I check, the out-of-the-box script apparently do not check the type of surface the character is standing on.
Your answer
![](https://koobas.hobune.stream/wayback/20220613093236im_/https://answers.unity.com/themes/thub/images/avi.jpg)