- Home /
Question by
Sazails · Jun 26, 2019 at 10:30 AM ·
jumpforcecharacter controller
How to make character controller jump?
Hello, how can I make controller jump up outside update function as I need to call it from another script. I have tried doing this, but it doesn't seem to work at all. Thank you.
public void Move(Vector3 move)
{
_moveDir = new Vector3(move.x, 0, move.z);
_moveDir = transform.TransformDirection(_moveDir);
_moveDir *= _moveSpeed;
_moveDir.y -= _gravity * Time.deltaTime;
_controller.Move(_moveDir * Time.deltaTime);
}
public void Jump()
{
if (_controller.isGrounded)
_moveDir.y = _jumpForce;
}
Comment
Answer by Hellium · Jun 26, 2019 at 10:32 AM
In your Move
function, you are resetting the value of moveDir.y
to 0. Try this way:
public void Move(Vector3 move)
{
_moveDir.x = move.x;
_moveDir.z = move.z;
_moveDir = transform.TransformDirection(_moveDir);
_moveDir *= _moveSpeed;
_moveDir.y -= _gravity * Time.deltaTime;
_controller.Move(_moveDir * Time.deltaTime);
}
public void Jump()
{
if (_controller.isGrounded)
_moveDir.y = _jumpForce;
}
Doesn't work.
$$anonymous$$y player on start sinks slowly down for a second and just goes bellow the floor and I get on the player y pos an error about floating-point precision error.
Your answer
![](https://koobas.hobune.stream/wayback/20220612203901im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
creating a jump pad for a character controller 2 Answers
How to make Sphere to jump? 2 Answers