- Home /
Problem with my Jumping script
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); }
Answer by Fierce Waffle · Mar 22, 2011 at 11:12 AM
Add a collider to the top of the sphere(head) and make it a trigger. And on the OnTriggerEnter function for the script on the platform you could make it "push" the character down. Or you could use a rigidbody character.
but how do i make it push down cos i could also say on collision type of function too too cant i? also isnt there a way to set that speed down to nothing instantly just so the gravity can take it back down ?
Your answer
Follow this Question
Related Questions
character jump on collision with a box 0 Answers
how the ball bounces of equal in angles? 1 Answer
Ball bounce problem 1 Answer
Unity2D Collision is bugged 0 Answers
Receiving information about getting hit by a Raycast 2 Answers