- Home /
Bouncing character like on a pogo stick
I am just using a basic player movement script that I found online, but what I am looking to do is modify this script so the character is constantly jumping. As if the character were bouncing on a pogo stick. I was thinking of just adding a loop that constantly press my jump button, but I don't think that's very efficient.
Any ideas? (below is my code)
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,
Input.GetAxis("Vertical"));
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 ItsK4rma · Sep 11, 2011 at 07:47 PM
After a good nights sleep I came back and just removed the 'moveDirection.y = jumpSpeed;' outside of the if statement, that way when the conteroller.isGrounded it will jump automatically.
Your answer
Follow this Question
Related Questions
character jump on collision with a box 0 Answers
need help with restricting the key press 0 Answers
character bounces on a box 0 Answers
Why can't my character jump 2 Answers
problem with 2d movement down slopes 0 Answers