- Home /
jumping with a character controller
i am making a simple 2d game and am using a character controller for my movement. i want the character to have a smooth jump but the script im using makes it instantly jump up and slowly fall back down. how can i make the jump smooth? this is the script im using:
var jump : int = 10;
function Update()
{
if(Input.GetButtonDown("Jump") && controller.isGrounded)
{
transform.Translate(0, jump * Time.deltaTime, 0);
}
}
See here http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.$$anonymous$$ove.html
the script has it all, movement and jump.
Answer by mattssonon · Nov 13, 2013 at 08:56 AM
Use .Move
or .SimpleMove
when using a Character Controller. Using the example code in http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html you would do this to jump:
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
if (controller.isGrounded && Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
thank you so much you just saved my life O_o I have searched the intire internet for a smooth jump on a character controler but it is nowhere! thank you so much ;-;
Answer by CriticalAngleStudios · Jun 04, 2019 at 05:42 AM
How does that work? It's setting the moveDirection's Y instantly. How can it possibly be smooth?
CharacterController.$$anonymous$$ove interpolates automatically I believe, although this is without actually checking the docs so please correct me if I am wrong
Answer by zedix28 · Apr 02, 2021 at 12:15 PM
The code that @mattssonon provided gets really glitchy when you collide with an object. How do I fix that?
Your answer
