Hello,
So i have been looking, but only found OnCollision2D able to detect which side of the Box collision was collided, however is there a trigger part of it? i tried to use collider, however my player object rigidbody2d is set dynamic, and the edge that i need the player to pass through is set and tried kinematic, and dynamic, but doesnt work… so the best thing and next idea is to use trigger… any ideas?
thanks in advance.
Triggers do not provide any information about the collision. All you get is the collider that was touched.
I do not understand your original problem. What are you trying to do here?
You can grab other, (the other collision object) gameobject position.
for on trigger
collider(other) → gameobject → position.
But to get the point of intersect you have to do more.
For on collision
You can get collision contact points in an array.
Trigger is more optimal because it doesn’t get these points and shows no concern for the contact aside whether any contact occurred.
for a collision type, it contains more detailed information about the intersect points. The intersect method in trigger would have to be created for you to get the same points. Or some of the same points. Because you wouldn’t need to get the same points because you could have used on collision for those points, you’d likely want less points. But this is veering now to another topic entirely.
On trigger returns a collider
And on Collision returns a collision event which comes bundled with some data to look at and use.
Hey chimcalcrux and SunBeamcoffe, sorry and thanks, so triggers wont be able to identify which side… no problem…
what I am trying to do is similar to creating a prefab that is instantiated when the player cross, however i think i have 1 or 2 ways to work around it… 1 is making a bool, depending on the angle or crossing of 2 colliders, will determine if the object needs to be created…
I was hoping On Trigger would have some data similar to Collider2d to determine the intersect or the angle or side of the box collider the the player hit… ohh well.
thank you
If you think about what triggers are, there is no defined “side” anyway, you just end up overlapped with it or you end up going through it.
If you enter a box trigger then a logical way to decide which way you “entered” is simply the velocity of the object moving into the trigger i.e. if it was moving right, you entered the left of the box.
1 Like
Note that if both these things (the thing moving and the box) were Kinematic then you can have the box not be a trigger and turn-on useFullKinematicContacts which reports contacts and because both are kinematic, they don’t have a collision response.
Note that in 2023.1 onwards, there’s a bunch of extra featrures that allow you to control things like force send/receive for colliders so you can, for instance, not use a trigger but instead just stop the box from sending forces. This’ll mean you’ll touch it but it won’t change the velocity of the thing touching it, very much like a trigger. The advantage being you’ll get contacts reported.
1 Like