well you see i got this from the unity scripting reference it works perfectly for my 2d style platformer. i have applied it to a sphere with a CC on it. but this is my problem. when making it jump under a platform i want it too come back down as soon as it hits the bottom of the platform above it as though it hit it and is bouncing back down to land on the floor but what is dose instead is presses up against the platform above it till it runs out of speed and comes back down.
any idea how i can make this happen can you show me i am new to java script and scripting in general. but anyway this is the script
/// This script moves the character controller forward
/// and sideways based on the arrow keys.
/// It also jumps when pressing space.
/// Make sure to attach a character controller to the same game object.
/// It is recommended that you make only one call to Move or SimpleMove per frame.
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}