Moving a box in 3d space

Hi I need help with applying movement to an object, I want the box to travel in x, y, z position based on the direction it is facing (x, y and z rotations), can anyone help, I thought this would be simple but I cant find anything that works. anyone got a code or example of this?

Something here should Centered on Created Origin | Babylon.js Documentation.

A basic attempt in a playground even it it does not work would give us a basis to work from.

EDIT Link corrected

3 Likes

I think the link you gave is broken,JohnK. :slight_smile:

1 Like

Heres a basic playground to work with. If I could just get movement based on the direction the blue box is facing id be happy. Im still confused by pivots etc.

https://playground.babylonjs.com/#P7P8I3

Perhaps locallyTranslate is what you need.

Initial forward vector is (0, 0, 1), a unit vector, then

box.locallyTranslate(new BABYLON.Vector3(0, 0, 1).scale(speed));

gives a forward movement

https://playground.babylonjs.com/#P7P8I3#1

1 Like

I like what you did there, however I have another issue now, as I rotate the box the rotational movements go out of whack, ideally when I rotate the box 90 degrees to the left the pitch should become the heading change. Im not sure how to achieve this the best way, have a look at my playground and you will see the problem.

Thanks for the assistance so far though.

You guys are awesome.

Floating Blue box | Babylon.js Playground (babylonjs.com)

here’s a new example

1 Like