Sign in to follow this  
Followers 0
negrant

babylon js attachToBone and changing animations

29 posts in this topic

Hi, guys! I have some problem. I am using function attachToBone for attaching a pistol to a hand of my game character. Sometimes if I change a character animations between shot and idle, pistol detaches from bone like on video. I think this is becouse in one moment a bone with pistol dos't animate, when an animation changes. But it is happens not always, often at low fps. And in old version of babylon 2.4 all works fine. But in version 2.5 it problem is appeared. Thanks for any considerations and ideas about it is problem. And it is problem if you ask me share on playground, this projects have many codes and models and other materials :) 

I shot the video

 

Share this post


Link to post
Share on other sites
8 hours ago, adam said:

Maybe you could make a really simple PG that reproduces the issue.

Okay, I did it  But I don't know how to load a models on the playground and I just create the archive file.

In my example I created many Elipse2D for simulating low FPS, you can change value of count of Elipses for manipulating of FPS, for each PC it is own count of elipses 

In example just you need it is click mause as many time as you can and you see that sphere, which attached to bone sometimes detaches for one moment :)

And one more fact, if you try to run this example in the version of babylon 2.4, all works fine, without a bone detaching

example.rar

Share this post


Link to post
Share on other sites
15 minutes ago, Dad72 said:

I think Adam found the problem and you have to miss this:

Adam says

Quote

Oh, you are simulating the movement of the character.

Yes, I am simulating the movement :) Like in first video in this topic

And I think, that a mesh attached to bone, must working with movements bones

Share this post


Link to post
Share on other sites
1 minute ago, adam said:

I thought I found a fix, but unfortunately it was a bug in my code. :(

Yes, I tried to write movement after render, but this do not helped  :)

I think the authors of the babylon js can help, if them will analyse version 2.5 and 2.4, because in the version 2.4 all works fine

Share this post


Link to post
Share on other sites

This is interesting:

http://www.babylonjs-playground.com/#OCCLB#32

That uses getAbsolutePosition of the bone instead of attachToBone.

To keep the sphere on the bone while the mesh is moving, you have to move the sphere by the velocity of the mesh.  

Try commenting out line 32 and adjusting the velocity of the mesh.

negrant likes this

Share this post


Link to post
Share on other sites
15 minutes ago, Dad72 said:

Have you tried with version 2.6 ?

Yes, example, which adam share on playgraond are using version 2.6-alpha

Share this post


Link to post
Share on other sites
28 minutes ago, adam said:

This is interesting:

http://www.babylonjs-playground.com/#OCCLB#32

That uses getAbsolutePosition of the bone instead of attachToBone.

To keep the sphere on the bone while the mesh is moving, you have to move the sphere by the velocity of the mesh.  

Try commenting out line 32 and adjusting the velocity of the mesh.

Good idea, but this are simplified version of my game, where player keeps a weapon and haves heavy animations like wave of the hand and I need know not only position of a bone, but rotation too

edit:

I understood, maybe I can use bone.getRotation, okay, tomorrow I will apply this idea to my game and then I will write what came of

Share this post


Link to post
Share on other sites
9 hours ago, adam said:

To keep the sphere on the bone while the mesh is moving, you have to move the sphere by the velocity of the mesh.  

I tried it's on my game and result even worse: tremble. Thank for help, will waiting for some news from the babylon developers

Share this post


Link to post
Share on other sites

You could also try this:

http://www.babylonjs-playground.com/#OCCLB#35

gunMesh.parent = characterMesh

and then copy the absolute position of the bone to the gun.

Notice I do not pass the mesh to the bone.getAbsolutePosition on this example.

with rotation:

http://www.babylonjs-playground.com/#OCCLB#36

It would be nice if attachToBone worked though, because I'm sure it's more efficient.

Share this post


Link to post
Share on other sites
30 minutes ago, negrant said:

If on playground you commented  scene.render(), but how can I run my game without render? 

That didn't fix the issue.  That just demonstrated that on the playground the issue seemed to be fixed with the extra render call in a separate renderLoop.

The best fix that I've been able to come up with is this:

http://www.babylonjs-playground.com/#OCCLB#36

I'm thinking that @Deltakosh can get attachToBone working the way it should in this situation, though.  Especially if it was working in 2.4. 

Share this post


Link to post
Share on other sites

adam, thank for help. Then I will be waiting for some help or informations from Deltakosh :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.