Throwing a snowball at YBot an have it stick there [ snowball.position = animated.vertex.position ? ]

I tried positioning a sphere at a mesh vertex position… and failed

Basic setup:
[Babylon.js Playground]

Goal:
The snowball mesh should ideally be fixed at dummy3 shoulder or any other position on his skin. And keep it there while the dummy3 is moving.

My thinking was to get a dummy3 vertex position and and use it as the snowball position. like this:

const dummy3 = scene.getMeshByName('YBot');
const positions = dummy3.getVerticesData(BABYLON.VertexBuffer.PositionKind);
const vpVertexNr = 0;

if(positions) {
  const pos = new BABYLON.Vector3(
    positions[vpVertexNr],
    positions[vpVertexNr + 1],
    positions[vpVertexNr + 2]
  );
}

This code isn’t included in the playground, cause it didn’t worked. for all vertices I tried, the snowball was positions between the heels but never on the skin.

thanks for your thoughts

That is one purpose of a playground.

You should note that as positions are in groups of three the indices needed to get the x, y, and z cooordinates for vertex vpVertexNr are

3 * vpVertexNr, 3 * vpVertexNr + 1, 3 * vpVertexNr + 2

If the code had been in the PG I could have done the changes

1 Like

I will add that as my signature…

1 Like

Thanks for your hints to improve my question.

here is the updated playground:
https://www.babylonjs-playground.com/#L0T4KN#1

It now contains a button to place the snowball randomly to a YBot vertex.
It feels like I’m on the right train, at least it looks like the snowball is now positioned at the YBot Skin before the skeleton changes the pose. But I have no clue on how to apply the skeleton changes to the snowball position.

thanks again for your help

give me some time, I found a few examples with related problems.
I post again with the result.

1 Like