Hello everyone, I’ll go straight to the point.
I’ve created 2 objects. ObjectA & ObjectB.
One is static(ObjectB) and one(ObjectA) has a script to go forward(towards ObjectB).
I want to add a Debug.Log when ObjectA collides(enters bounding box) of ObjectB.
How can I Implement this? I know I can do this w/RigidBody and wo/Physics.
Where my question is going is, my gameplay is a 2D Zeldaish Moving world.
What would be your best approach to do the Debug.Log.
and How?
Thanks for your time and answers!
The solution is triggers!
This is a key part of the docs to read: Unity - Scripting API: Collider.OnTriggerEnter(Collider)
Add colliders to both objects, and a rigid body to Object A (at least 1 object involved has to have a rigid body for triggers to work).
If you don’t want Object A to move under physics, set its rigid body to ‘kinematic’ - that means it exists in the physics world but you just move it via script rather than using proper physics.
Set Object B’s collider to be a trigger (its in the properties). This will mean that when object A enters the collider it will call ‘OnTriggerEnter’ on any scripts on either object.
That should do it for the scenario you describe. It’s a little different if you want objects to be bouncing around under physics instead (you use the OnCollisionEnter function instead) but the same principle applies.
I also had really a lot of problems when configuring the collision between game objects.
After years I wrote every tips in this article https://gamedevelopertips.com/unity-collision-detection-2d/, I’m sure it’ll be helpful if you want to set up properly you collider/triggers property.