Sprite actionmanager and OnIntersectionEnterTrigger /ExitTrigger

Hay Iam trying to trigger “sprite ManagerPlayer”
with OnIntersectionEnterTrigger and ExitTrigger.

But Iam not sure if that is possible at this time
(ActionManager.OnPickTrigger works just fine)

https://www.babylonjs-playground.com/#9RUHH#5

anyone any suggestions

Hi nabi.

I did some experiments… https://www.babylonjs-playground.com/#9RUHH#44

ActionManager OnIntersectionEnter/Exit triggers… are not designed to be used with sprites, I think. Those triggers are for mesh, and sprites are not really (classic) mesh. A single sprite is similar to one “cell” of a subdivided/tessellated ground-grid (like one cell of an html table) (I hear). :slight_smile: P.O.P. - portion of plane. :slight_smile:

OnPointerOver/Out triggers on sprites… works fine (because a mouse-pointer is a 2d thing, too). But not onIntersectionEnter/Exit. I think maybe sprites are too flat. They have no bounding box depth. It is like trying to mesh-intersect with fog. :slight_smile:

I haven’t experimented very much… with mixing sprites (2d-like stuff) with mesh (3d stuff)… and trying intersecting/colliding between them. Interesting challenge… let’s listen for more comments, including yours. :slight_smile:

Hay Wingnut
Not sure if sprite is 2d I think its actually a 3d plane
(hide img link and you see a plane )

I normally try to figure out problems myself for a better inside experience
so I tried different methods and could not find anything in the
documentation about sprite/mesh intersection.

Here is also my PG with full sphere intersection of the Sprite manager,
its not so hard to hit the sprite fullsize.
https://www.babylonjs-playground.com/#PZTC5P#4

OnIntersectionEnter/ExitTrigger are indeed only working for meshes: a sprite is not a mesh, it does not subclass AbstractMesh nor Mesh.

So I don’t think what you want to do is possible currently (without having to write custom code, of course).

https://doc.babylonjs.com/api/

Look at API for sprite, spriteManager, and mesh. Notice the Hierarchy section. Mesh is a subclass of AbstractMesh, which is a subclass of TransformNode, which is a subClass of Node.

Sprites and SpriteManagers are NOT in this class. They are not Mesh-class objects.

Yes, theoretically, planes and cells of sub-divided planes… ARE 3d. But still, BJS sprites or sprite managers… are not mesh-class objects. They don’t inherit from any upper/super -class, as you can see by their hierarchy sections of the API. shrug

I don’t think this is a bug. But still, we could use some ideas how to make something work, eh? POSSIBLY… we could use “SPS”… solid particle system… which can be told to ACT like sprites… yet possibly still allow 3d intersections.

https://www.babylonjs-playground.com/#CNMNR#1 Some SERIOUS intersecting happening there… and without an actionManager… I think. SPS is very powerful… can easily make sprite-like panels or boxes and map textures onto them. Maybe even animated textures. It will take some time to tour all the solid particle system demos… @jerome has built MANY experiments with them… to test performance limits. It’s worth studying, and is, in some ways, “advanced sprites”, I suppose.

SPS “digests” real BJS MESH planes… just fine. It can eat 100k of 'em in one sitting. :slight_smile:

Yep Wingnut thanks for the input You seem to be as interested as I am.
I was thinking the other way around.
If its pickable it must be trigable somehow!! :grinning:

1 Like

My pleasure. Want to go a bit deeper?

Sprites have RAY intersecting! Babylon.js/spriteManager.ts at master · BabylonJS/Babylon.js · GitHub

(I suspect the pointer clicking… uses a ray, too.)

SO… let’s pretend that you “fire” a ray… from the center of sphere… to sprite.position (in render loop, every 1/10th second). Or maybe better… all sprites fire rays at sphere… ever 1/10th second. Check… if pickray.distance < 0.01… THEY COLLIDED! :slight_smile:

I have never used spriteManager ray-intersect code, but there it is… we see it. It might be difficult to search for playgrounds that use that feature. hmm.

I DID do a really bad “rays being periodically shot… to test for subMesh intersections” playground… but it didn’t use sprites. It was a mesh-to-subMesh home-made intersection “engine”. Badly coded… by me… https://www.babylonjs-playground.com/#1B0PF#7 (watch js console and sphere colors for ray-distance-based intersect testing results). Gruesome.

See all those… ray = BABYLON.Ray.CreateNewFromTo(balloon3.position, sphere.position) ??

Yours could be similar. … change balloon3 to spriteManager.sprites[0].position… or something. Could be vector2 - to - vector3 conversion hassles, there.

OR, they might be MUCH different. Something like… spriteManager.intersects(ray: Ray, camera: Camera, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean)…

Crap, it wants a camera for one of its params. We want to give it a sphere. hmm.

All we need is a distance from sprite to sphere. Perhaps subtract sprite.position vec2… from sphere.position vec3? hmm.

spriteManager.intersects() might not be the best route… for fake mesh-to-sprite intersection testing. More thinkin’. :slight_smile:

Here is a playground where someone is treating a plain ol’ plane… as if it were a sprite. https://playground.babylonjs.com/#2GYRPB#4 I bet actionManager intersection triggers work fine on THAT sprite. :slight_smile: Jerome donated another… here. Sprites on a mesh… yum. Ready for 3d player? Intersecting is REALLY a nightmare, then. :slight_smile:

Yeah, I know you like to figure out stuff for yourself, but a little learning curve rocket-assist never hurt anyone, did it? Ok, maybe a few, but not too many. heh.