- Home /
Question by
alihusen · Apr 24, 2019 at 09:35 PM ·
collisioncolliderjumping object
how do i make my charectar only jump if it collide with a specific object
iam trying to make my Sphere (charectar) only jump when it collide with for example a cube( a floor ) or so as long as my charectar is colliding with that object that i choose it will jump by the way iam using a regidbody and my charectar is a ball(Sphere)
Comment
Answer by highpockets · Apr 24, 2019 at 09:34 PM
You can AddForce() or apply velocity in the world y direction when there is a collision ( OnCollisionEnter()) with the specified object:
float jumpForce = 40.0f;
OnCollisionEnter(Collider other){
if(other.tag == “TheTagNameOfTheObjectThat MakesThePlayerJump”){
transform.rigidbody.AddForce(0,jumpForce, 0);
}
}
Your answer
Follow this Question
Related Questions
Collision problem 0 Answers
Tilemap Collider 2D preventing objects from moving 2 Answers
Box collider didn't jump with player 1 Answer
For moving Quad character box collaider or mesh collaider 0 Answers