Question by
chetan_dabhi · Sep 07, 2016 at 12:47 PM ·
colliderrigidbody2d
I want your platform to not fall down when the player collides with the bottom part of it ?
In my unity game I've arrange different platform ,when my player collide with upper part of the platform so platform falling down but issue that when my player collide to platform buttom of part so platform falling down.
void OnCollisionEnter2D(Collision2D target)
{
if (target.gameObject.tag == "Player") {
gameObject.GetComponent<Rigidbody2D> ().isKinematic = false;
}
}
Comment
Answer by FirePlantGames · Sep 09, 2016 at 02:18 AM
Check to see if the player is falling, or rising. Also, it's a good idea to set up a reference to your components as GetComponent() is very slow.
Rigidbody2D rb;
void Start ()
{
rb = GameObject.FindWithTag ("Player").GetComponent <Rigidbody2D>();
}
void OnCollisionEnter2D (Collision2D target)
{
if (target.gameObject.tag == "Player")
{
if (rb.velocity.y <= 0)
gameObject.GetComponent<Rigidbody2D> ().isKinematic = false;
else
return;
}
}
(You may have to change the = I can't remember if velocity pulls down, or up)
Your answer
![](https://koobas.hobune.stream/wayback/20220612092329im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player Sticking to walls 1 Answer
Rigidbody2D to go through Box Collider 2D 1 Answer
Why Object2D jump out collision? 1 Answer
rolling sphere grounded 0 Answers
¿Why wont child move with parent? 0 Answers