maybe it’s just too late. But I cannot seem to find a way to send a message to a class instance of a mesh I picked.
F.e. a bullet casts a ray forward where it’ll hit. Now it want’s to tell the targets Target.ts class which contains the picked mesh it will be hit. How would I (or the bullet ) do that?
With a fresh brain I still couldn’t find a built-in solution for this. So I subclassed Mesh like this:
import { Mesh } from "@babylonjs/core";
import { SimpleEventDispatcher } from "strongly-typed-events";
export class CustomMesh extends Mesh {
public onPick = new SimpleEventDispatcher<string>();
constructor(mesh: Mesh) {
super(mesh.name, mesh.getScene(), mesh.parent, mesh);
}
}
Like this, on picking the mesh with a ray, I can check if it’s a CustomMesh and send an event to the owning class of the mesh, which subscribed to its onPick EventDispatcher.
Still, if there’s a built-in - probably more solid way - I’d be interested
Hmm, don’t waste your time on it as my solution works ok for me. But if you want, correct me if I’m wrong.
Wouldn’t the behavior be executed on the target. So the onPick would also happen on the target mesh?!
How would the bullet be able to send some info to the target without bouncing events back and forth?