Jump to content

[SOLVED]How to properly rotate a mesh with yours physic Imporstor?


cpu_sam
 Share

Recommended Posts

Hello, I'm trying to rotate a mesh with mesh.rotate(BABYLON.Axis.Y, 0.1, BABYLON.Space.LOCAL) but like it's attached to a physicsImpostor the impostor not rotate, only the mesh. And so, I'm trying to do this movement: http://playground.babylonjs.com/#NFJFE

Following the example to my mesh go ahead I must rotate a little and move on the axis target (like Z is the front), but the "obvious" code about not works with impostor, and I supose that I should rotate it to make the same effect of the air plane's link.

I'm a 2d programmer and trying to learn 3d with babylonJS, I still not learn about quaternions (planning to see so on)
Thanks for any help.
NOTE: I've searched in google many times but no luck

Link to comment
Share on other sites

Thank you for your help Prime8.

Well, let me explain better. For example: I have a block in the position (0,0,0), for default I use the local axis Z (positive) as the front of object.

When I run block.rotate(BABYLON.Axis.Y, 45 degrees, BABYLON.Space.LOCAL);//45 degrees just for calc

So the front of object stays in 45 degrees, and the movement of block should be in 45 degrees when move with block.position.z += 1, and not just in the axis Z, but will be in two axis (X and Z). Like this example of air plane: http://playground.babylonjs.com/#NFJFE

My problem is: I cannot move in that way (in X and Z when rotate the front in Y axis), the block just follow the world axis instead of follow the local rotate axis o block (follow the front of it)

So, I think that impostor wasn't rotate, but just the mesh.

 

Link to comment
Share on other sites

Man, I solved the problem hehehe I was remade the example and studying the air plane example and I notice that in the air plane example they don't move like this: airPlane.position.z += 1; but they use the translate method, like this: airPlane.translate(BABYLON.Axis.Z, speed, BABYLON.Space.LOCAL);

For now, thank you Pryme8 and I will let my example here in the case of some one need (attached)

 

3dMovement.zip

Link to comment
Share on other sites

Hi cpu_sam... and P8.  Sam, mesh that have impostors... are sometimes "moved" with applyImpulse() or setLinearVelocity().  There are also physics springs and motors that can translate a mesh-with-impostor.

https://www.babylonjs-playground.com/#15AFCG#24

There's a little applyImpulse playground.

WASD keys for the camera nav.

Arrow keys for impulses.

There is a small amount of friction on ground and box, so, box has SOME tendency to tip.

Here is the same playground... except it uses setLinearVelocity.

https://www.babylonjs-playground.com/#15AFCG#25

Rotations can be done with setAngularVelocity(), or, you can use a fancy 2-impulse "twist" method, too.

One more?  Ok.  https://www.babylonjs-playground.com/#15AFCG#27

Here, I am using the arrow keys to do various 'rotate' and 'translate' commands, making sure the physics impostors are staying sync'd.  Looking good.

I think you have a good solution.  I downloaded, unzipped, and looked-over your scene (thx for providing that zip). 

I believe it's ready for physics-enabled.  Looks good.  Fun experiments ahead for you.  Welcome to 3D, BJS-style.  You're doing great.

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