Hi,
I’m new to C# and Unity so pls bear with me. How can I check if something is colliding with let’s say a jump pad and the object that is colliding has a rigibody2D so I can manipulate the objects rigibody2d velocity.y? I looked thru the documentation but I still don’t get it. I have in the Jump Pad with a rigibody2d Body type; Dynamic, Box Collider2D Is trigger; checked, and in my Box/Crate the same as Jump Pad only Box Collider2D Is trigger; not checked. Here is a gif so you know what I mean.
Any help is appreciated. Thank you for your time.
I’m not the best at coding either, but I have a few solutions.
- I’m not sure but based on what I read (I’m pretty bad at reading) you have two trigger colliders and you’re trying to get them to collide. Which does not work since you need at least one collider to not be trigger. (I think, Take with a grain of salt)
- I wouldn’t use velocity because I like to use rigidbody.addforce . I think it’s more efficient? (I know, I’m pretty bad.)
- you’re trying to change just the y velocity. I know it’s not the same but, if you were to change the position of a camera, you need a new vector 3 with the cameras x, y, z plus the added changes, maybe its the same for the velocity.
public class JumpPad : MonoBehaviour
{
private GameObject _gameObject;
private Rigidbody2D _rigibody2d;
l void OnTriggerEnter2D(Collider2D collider)
{
_gameObject = GameObject.FindGameObjectWithTag("Crate");
_rigibody2d = _gameObject.GetComponent<Rigidbody2D>();
_rigibody2d.velocity = new Vector2(0, 22f);
}
This works but it works only for one crate/box I’m looking for a way to check if any GameObject with rigibody2d collides and if so it should “jump/bounce” on the jump pad.
@Jadecraft4 Thank you for the feedback. 1. I have the colliders and triggers set if it is what you mean.
2.I tried with rigibody2d.addforce and it works the same way as new Vector2(0, 22f)
3. I don’t understand this part I don’t know why I need Vector3 or the Z-axis on 2d platformer? If you mean that.