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

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

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

##### Share on other sites

A PG showing what is going on with the method you are trying would help.

##### Share on other sites

Ok, I will make two example. Just give me some time.

##### Share on other sites

Then I will help ^_^.

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

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

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.

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.

##### Share on other sites

5 hours ago, Wingnut said:

Cool example man, I still not tried to move with impostor, but surely I will study your example. Thank you.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.