- Home /
Problem with 2 Rigidbodies having respective colliders (2d)
I am making a 2d vertical scrolling platformer, I have an auto-jump script attached to the platforms:
public class AutoJump : MonoBehaviour {
private GameObject Player;
void OnTriggerStay2D(Collider2D other)
{
GameObject Player = GameObject.FindGameObjectWithTag ("Player");
if (Player)
{
Player.rigidbody2D.AddForce (Vector2.up * 375);
}
}
}
The player has a rigidbody, box collider(trigger) and another box collider attached to it. When I spawn an enemy to the scene the player instantly jumps too high i.e. the addforce increases from 375 to a very big number.
Answer by Pyrian · Jun 10, 2014 at 03:31 PM
Try replacing "if (Player)" with "if (other.gameObject.tag == "Player")". Right now you're jumping the player no matter what lands on the AutoJump. So, your enemy is probably walking around on it, launching the player ever higher...
Your answer
![](https://koobas.hobune.stream/wayback/20220613151215im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody2D x velocity not moving unless placed in FixedUpdate 1 Answer
Adding force to rigidbody2d to slide 1 Answer
Rigidbody2D is kind of flying instead of falling when the child box is colliding 1 Answer
How do add force to the left (x-axis) 2 Answers
Using direction and Rigidbody2D.AddForce() to move towards object. 1 Answer