Jump to content

babylon js attachToBone and changing animations


Koroldev
 Share

Recommended Posts

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

 

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

After all that, I think the very first PG actually works correctly.

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

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

Edit:

I think it's because you are rendering the scene again.  Here I commented out scene.render():

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

So it actually isn't the ideal solution.

 

Link to comment
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. 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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