I’m using a Character Controller on a terrain. I’m outputting the result of collisionFlags from controller.Move() and when the character is stood flat on the terrain, the collisionFlag flickers from ‘none’ to ‘below’. I want it to give a solid ‘below’ reading when contacting the terrain.
function Update() {
var turn: float = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
if (controller.isGrounded) {
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
grounded = IsGrounded();
// Apply gravity
if (IsGrounded()) {
moveDirection.y = 0.0;
} else {
moveDirection.y -= gravity * Time.deltaTime;
}
// Move the controller
collisionFlags = controller.Move(moveDirection * Time.deltaTime);
//Debug.Log(collisionFlags.ToString());
}
public function IsGrounded () {
return (collisionFlags & CollisionFlags.CollidedBelow) != 0;
}
I’d imagine its something to do with the contacting of the normal’s with the terrain…but there may be a more simple solution.
Help is appreciated