Character controller and Moving platform

Im using technology from 2D platform tutorial.

controller hit.normal.y >0.8
platform = hit.collider So when character is grounded on any platform
My cobtroller transform.position=transform.position+Distance(platform traveled)
When platforms moving X ,Z or -Y everything is fantastic , but +Y… :frowning:
Adding the platform speed to my controller VerticalVelocity component ,or keeping controller sticky to the last platform - is not right decisions.
Im trying to
if (!PhysicsRaycast (transform.position,-Vector3.up,2))
->detach my controller from platform and let em fly.But this is so noobby :shock:
animatePhysics on/off,adding rigidbodies,setting Time.fixedTime=0.0001 etc does not help :frowning:
Help anyone :sweat_smile:

Hi Mr Andrew,

This was an issue I ran into a few months ago too with the Y moving platform thing. I was doing a first person style, but, maybe you can get some useful info or even use one of these. I think it’s because you’re using the Character Controller which is just about useless for vertical moving platforms (as far as I know).

Here’s a link to a couple of scripts that you can choose from that can solve that, if you’re having trouble implementing these, just ask:

http://www.unifycommunity.com/wiki/index.php?title=PhysicsFPSWalker

Hope this helps,
Nathan

The easiest way to handle this problem is to have a trigger on the platform that makes the player the child of the vertical platform while on top of it.

Basically,

function OnTriggerEnter(hit : Collider) 
{
   hit.transform.parent = transform;
}

OnTriggerExit(hit : Collider)
{
   hit.transform.parent = null;
}

Of course, you’ll still need to have gravity working in order to avoid a floating character, but that’s not that big a deal. It’s only when the platform moves that the problems appear, anyway.

If you’re working with rigidbodies, you have to consider following points for elevators to work properly (and make lots of other things work better):

  • All operations have to be done in FixedUpdate()
  • All moving parts need to have a rigidbody attached, possibly with isKinematic enabled
  • Instead of using the Transform to move a rigidbody, use Rigidbody.MovePosition() and Rigidbody.MoveRotation()
    I haven’t worked with the character controller but with these three points, most oddities with animating rigidbodies should go away.

Thanks.Now im simply using 2 types of platforms.Fast and slow moving,and calculate controller movement according platforms type

As far as i can see, controller transform.position=transform.position + Distance( platform travelled) is the same way as parenting :shock: