- Home /
Answer by MC HALO · Apr 19, 2011 at 12:50 AM
var jump : float = 4f;
function Update (){
if(Input.GetKey(KeyCode.LeftShift)){
//rigidbody.velocity = Vector3(0 ,jump,0 ); rigidbody.AddForce(Vector3.up * jump);
}
}
you can use //rigidbody.velocity = Vector3(0 ,jump,0 ); or // rigidbody.AddForce(Vector3.up * jump); its up to you. This is how i would make a simple jump using rigidbody :)
hope this helps
Ok this is the Updated script, this one does not require any rigidbody it only needs a character controller. But just to let you know you don't even need to add a character controller to the player because the script will add it automatically :) once the script is added.
The script will also allow you to walk up and down using the vertical key "A, D" and using the Horizontal keys " W , S " you can rotate the player. to make sure it is working make the camera the child of the object :)
anyway's here is the script:
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
var gravity = 20.0;
var JumpSpeed : float = 10;
var rotatespeed : float = 5;
var speed : float = 10;
function Update () {
var controller : CharacterController = GetComponent (CharacterController);
//Rotate around y -axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotatespeed, 0);
//move forward / backwords Vertical
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(grounded){
if (Input.GetButton("Jump")){
moveDirection.y = JumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
yea there is you can use character controller i will update it for you so you can have the player jump with the character controller ins$$anonymous$$d :)
how can i get rid of bounce, because i jump then bounce bounce bounce for a while and it shakes the camera and looks terrible
Answer by Rafaelski · Oct 12, 2020 at 11:59 PM
bool jump = CrossPlatformInputManager.GetButtonDown("Fire 3");
Your answer
![](https://koobas.hobune.stream/wayback/20220613123652im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check if float is increasing/decreasing 1 Answer
Another Slow Fall Problem... 2 Answers
Triple Jump C# Script 1 Answer
2d Jumping Problem 1 Answer
(New input system) How to queue a jump before you touch the ground? 0 Answers