onCollisonEnter two objects

Hello there i’m currently working on a project where i want to detect collision with 2 box colliders and perform an action on the if statement.

Can someone help me?

Original Post on Discord

by user 388785392188653589

Whats the code showing? You can just implement onCollisionEnter on a component that is on the box collider.

image.png

by user 388785392188653589

There are some samples in here using that (for e.g. changing the color on collision: GitHub - needle-tools/needle-engine-samples: Live: https://engine.needle.tools/samples 🌵 Needle Engine sample scenes - use as examples and as a reference for learning 😊)

by user 388785392188653589

That’s a callback function and invoked by the physics engine

you dont invoke it with a box collider component

see https://github.com/needle-tools/needle-engine-samples/blob/main/assets/Runtime/_Shared/SampleScripts~/ChangeColorOnCollision.ts

or https://github.com/needle-tools/needle-engine-samples/blob/main/assets/Runtime/_Shared/SampleScripts~/PhysicsCollision.ts

here’s a sample in action https://engine.needle.tools/samples/basic-physics/

Thx!

by user 388785392188653589