- Home /
Rigidbody jump
I'm trying to get the player character to jump using a rigidbody. So far it's working but not too well. I need the jump to be faster (increasing the force of the jump just makes it go higher). Also, I need the distance the player travels to be an arc shape that travels exactly +2 in the z direction each time, how do i guarantee it doesn't stray from this? I tried Slerp and that worked perfectly but wouldn't automatically bounce on collision or update it's location, so I'm trying rigidbodies. The gameobjects the player is bouncing off are tagged "TileFix" and "TileMove, when the player collides, they jump automatically again.
public GameObject player;
Rigidbody rb;
public float jumpForce;
public Vector3 jump;
private bool isGrounded;
void Start(){
rb = GetComponent<Rigidbody>();
player = GameObject.FindGameObjectWithTag("Player");
isGrounded=false;
}
void Update(){
if (isGrounded)
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("TileFix") || other.gameObject.CompareTag("TileMove"))
{
Debug.Log("Landed");
isGrounded = true;
}
}
Your answer
Follow this Question
Related Questions
How to give jump without rigidboy by using transform? 1 Answer
How to make character with rigid body jump to specific location? 0 Answers
How do you make a sphere jump with a rigidbody attached to it? 1 Answer
Basic Jump Pad help 2 Answers
Axis Aligned Bounding Box Vs Object Orientated Bounding Box 2 Answers