onCollision callback

Hey Guys, I’m new to babylonjs so sorry for the newb question. I am looking to send data to another game object when it collides with another object. For example. If I have 2 objects, ActorA, and ActorB. I am dragging ActorA and it collides with ActorB. My events for ActorA will let me know that it has collided with ActorB. How can I send data from ActorA to ActorB on this event? Hopefully, that makes sense. Thanks

In general such things can be solved with the observer design pattern.

JavaScript Observer Design Pattern - Dofactory

I knew you were going to say that. Observers are my Achilles heel. Would you mind doing a quick crude example?

  carAggregate.body.setCollisionCallbackEnabled(true);
  const observable = carAggregate.body.getCollisionObservable();
  observable.add((collisionEvent) => {
      // Process collisions for the player
      // console.log("Collide " + collisionEvent.collidedAgainst.transformNode.name);
      if (collisionEvent.collider.name == "Car")
      {
          
      }
      else if (collisionEvent.collidedAgainst.transformNode.name.includes("Building"))
      {

      }
  });

Hope it helps

Common Observer Example

Only the Player2 “listens” the moves of Player1 and follows him.

Common Observer Example | Babylon.js Playground (babylonjs-playground.com)