Answers for "how to add jumping unity with controller"

C#
0

how to add jumping unity with controller

public float jumpForce;
public float gravity;
Vector3 velocity;
public CharacterController controller;
void Update()
{
  //this also add gravity
	velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);
    
    if(Input.GetKeyDown(KeyCode.Space))
    {
    	velocity.y = Mathf.Sqrt(jumpForce * -2f * gravity);
    }
}
Posted by: Guest on August-09-2021

Code answers related to "how to add jumping unity with controller"

C# Answers by Framework

Browse Popular Code Answers by Language