I was going to report this as a bug, but i want to make sure that i’m not doing anything stupid first.
I have a very simple scene with a character collider and a movement script.
private var controller : CharacterController;
var velocity : Vector3;
private var playerGravity : Vector3 = Vector3(0,-30,0);
private var jumpVel : float = 10.0;
function Start()
{
controller = GetComponent(CharacterController);
}
var flags : CollisionFlags = 0;;
var timeColliding : float = 0;
function Update () {
// move right 1m a second;
velocity.x += 1 * Time.deltaTime;
// apply player gravity
velocity += playerGravity * Time.deltaTime;
// move the controller
flags = controller.Move(velocity * Time.deltaTime);
// Respond to any collision we might have had
if((flags CollisionFlags.CollidedBelow) != 0)
{
velocity.y = jumpVel;//0;
// just making sure the problem is only for hitting your head
timeColliding = 0;
}
if ((flags CollisionFlags.CollidedAbove) != 0)
{
velocity.y = 0; //-jumpVel;
// increment collide timer
timeColliding += Time.deltaTime;
}
}
The script is set to make the controller to bounce up when it hits the ground, and then lose velocity and fall normally when it hits the ceiling.
The bounce on the ground part works fine however, on colliding above, the controller moves very slowly down for over a second and then starts falling normally.
What appears to be happening is that CollidedAbove flag seems to be set for a long time after the controller itself has moved away from the object it hit. ( i’ve set a variable called TimeColliding so you can see whats happening)
As a test I tried mirroring gravity and flipping the jumpVel values. The Behaviour was as I expected, which further points to the CollidedAbove flag.
As an additional note, this only happens when the velocity.x is greater than 0;
I have attached a package file to this post.
Any help appreciated.