Jump to content

** SOLVED ** moveWithCollisions - establish meshes new position

Richard C

Recommended Posts

Hi again

I have a box being used as an Empty with 4 children. I am using moveWithCollisions on all 4 using the box mesh as the collider. When collided with the ground I have particles emitted from the vertices of each child mesh. All works well EXCEPT the particles are emitted from the children's original starting position rather than the point of collision where I want them to emit.

I assumed getVerticesData(BABYLON.VertexBuffer.PositionKind) followed by .updateVerticesData(BABYLON.VertexBuffer.PositionKind),would establish the new position of each mesh but it doesn't. 

So my question is.......

How to establish the new position of each child and therefore the vertices positions of each.



Edited by Richard C
Link to comment
Share on other sites

Some insight:  https://www.babylonjs-playground.com/#2A4NUR#31

This particles-from-verts demo was made by SOMEBODY.  I don't know lots about it, but I love it.  If FOUR of these were parented to a central gizmo/blank... that had a collision .ellipsoid re-sized to "enclose" all 4 of its children (like 4 landing pads beneath a mini-submarine)... then... would this particles-from-verts move its vert-positions WITH the positioning of the parent?

Is there something in this particles-from-verts demo... that would cause problems IF its emitter box/sphere... were parented, and the parent was used to move the children?

I'll probably test... parent 4 of these "sprayers" to a central mesh, and try some stuff... if I get a chance.

I think I would put checkCollisions on all 4 children, and not use blank box ellipsoid to surround children.  I would monitor for each children's collisions, and then turn on the sprayer for that child.  :)  *shrug*  I'm probably off-topic.

As a side note... Richard... do you know that a particle emitter can spray in all directions from a single point... IF the .direction1 and .direction2 values are set properly?  You don't NEED sphere doing particles-from-verts... to get a nice "spray in all directions".  (in case you were trying to get a spray-in-all-directions).  Using non-particles-from-verts, and instead doing a good .direction1 and .direction2... will be easier.  In other words, if all-direction-emitting is what you are after, I would advise saying goodbye to "emit-from-verts" and hello to great particleSystem knob setting.  Also keep in mind that a particle system's .emitter can be a vector3... which isn't a mesh at all.  It's just a place in space.  I love that.  kbye

Link to comment
Share on other sites

@Deltakosh I am not updating the geometry per se. I am still on the same project as I have been in the recent opsts. I have a model submarine that dives from the surface to the seabed and the particles are to simulate the sand 'cloud' that is kicked up when the sub lands on the seabed.

The sub dives and using moveWithCollisions to detect when the sub hits the seabed.


Link to comment
Share on other sites

Yeah... .updateVerticesData(BABYLON.VertexBuffer.PositionKind) is probably not going to do anything useful.

The vert sprayers aren't in the new location... after the move, right?  They stayed in old position?  Yeah, it has to be something with that spray-from-verts demo.  Did you borrow some code from that demo (to get your spray-from-verts happening), RC?  Bet so.  :)

Link to comment
Share on other sites


Thanks pal. That is the very PG I used to learn particle emission from vertices!

2 things ........

the bottom of the sub is not rectangular.square so the verts are not linear. Additionally, the children are not a plane but need to be an arc to get the correct sand cloud shape. If you picture such an event you will remember that sand 'kicked' up is far more of a cloud than square/rectangle/linear.

All would be well if I could establish the position of each child at the point of collision. The seabed isn't flat of course- so the depth varies along the sub's path. It seems that moveWithCollision is displaying as it should but not updating the actually position of each child/mesh.

It will be helpful to see what you come up with if you get the chance.



Link to comment
Share on other sites

Well, for a quickie... https://www.babylonjs-playground.com/#1PQT7P#6

Notice that the shape of the mesh... isn't important.  What IS important... is lines 52-56.

Although understanding min/max emitbox (where upon the mesh... particles will emit-from) and direction1/2 (what direction ranges are the particles allowed to fly-within)... are not easy, they are everything.

You've seen this demo before, or one similar.  We have set our min/max emitbox so that particles are ONLY allowed to leave the box... at a "belt-line" around the center of the box.  Line 55 and 56 are SIZES... and both my Y values are set to zero.  Set them to -.1 and +.1, and the belt-line will get taller (wider belt)... but still be around center.

Notice that, no matter WHERE on the mesh... the particles are emitted-from... they are ONLY allowed to fly upward and leftward.  Even particles that are emitted on the right side of the box... are NOT allowed to fly right-ward.  Our direction1 and direction2 "range" (lines 52/53) are set so that particles can ONLY fly left and up.

Having this new "power"... do you REALLY need particles-from-verts system?  Can't you just use your emitbox powers and your direction powers... and leave behind particles-from-verts?

What's that?  Emit from front upper left corner of box, only?  That means my emitBox is -1, 1, -1, to -1, 1, -1  ... for this 2 by 2 by 2 box, right?  Let's try it.  How about ps1.minEmitBox = new BABYLON.Vector3(-1.5, 1.5, -1.5); and ps1.maxEmitBox = new BABYLON.Vector3(-1.5, 1.5, -1.5);   ... which should make the emit box/point be out in space... near the top left front corner.  Let's try it.  :)  Fun!


It is my theory... that if you avoid particle-from-verts, your "emitter points left-behind after move" -problem will go away.  (and your particle clouds will have less "stringy-ness" and more randomness.)  Also, now you have the power to make your children be ANY shape, because you know the 4 particleSystem knobs that control your spray nozzle direction and field-of-spray angle.  :)

I'm easy.  I will still try to get your four parented "from-verts" demo working, if wanted.  Maybe somebody else will make that tester... I'm kind of lazy today.  :D

Link to comment
Share on other sites

I have tried various ways similar to your suggestion. The 'from verts' is giving me the 'shape I want my only real issue is getting the positions of the verts onCollide after the moveWithCollisions. 

So really there is only one Q to answer - how do I establish the actual position of the child mesh so that I can get to the verts.


Link to comment
Share on other sites

@Wingnut - That's the one my friend.

An alternative I have just been playing with is based on what Deltkosh said........

I know the position of the parent box on collision. The emitters are always the same distance/position away from the empty and therefore I could reposition the child relative to the empty and then emit.

But getAbsolutePosition is much easier and less code and works.

Problem solved.

Thanks again both.

PS How do I mark/tag this topic as solved?

Link to comment
Share on other sites

Good deal!

Better start a new thread to ask how to mark questions as solved.  ;)

No, no, don't do it, I was only joking-around, of course.  hehe.


Check this out:  https://www.babylonjs-playground.com/#2A4NUR#33


I discovered that each "shape" used to spray-from-verts... is actually TWO shapes... a shape and a gizmo.  In the above supersprayer, gizmos are parented to shapes, and shapes are parented to shape0 box.  MoveWithCollisions on the box, and weeeeeee.... away we go... flying confetti machine.  :)  Too fun!  View from side and use control-dragging to stay with it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...