Rotation doesn't update position (fake (0,0,0) gravity)

Hi everyone,

Here a playground.

So the idea is that I have a car driving in a custom planet and since it’s not possible to configure the gravity on a precise point (the point (0,0,0) in my case) so I bypass this by doing a rotation on my car on the pivot (0,0,0).

However, during the rotation the position of the car (show in the command console.log(car.position)) does not change absolutely what bothers me afterwards for the detection of intersection between two meshes.

I wanted to know then if it was possible to fix this or if there is any other method that will give me the end result that I want.

Thank you all.

Here is an example of what i want to do :

You could parent your car to a transform.

The car would have a position of (0, radius, 0) and apply the rotation to the parent instead.

This should do the trick.

hi,

So if I understood you correctly instead of doing this:

    var car = BABYLON.MeshBuilder.CreateBox("car", {width : 0.2, height : 0.2, depth : 0.5}, scene); 
    car.position = new BABYLON.Vector3(0,4.1,0);
    let pivot = new BABYLON.Mesh("pivot", scene);
    pivot.parent = car;
    const pivotAt = new BABYLON.Vector3(0, 0, 0);
    const relativePosition = pivotAt.subtract(car.position);
    car.setPivotPoint(relativePosition);
    scene.registerBeforeRender(function (){
        console.log(car.position)
        car.rotate(new BABYLON.Vector3(1, 0, 0), -0.02, BABYLON.Space.LOCAL);
    })

I put this :

    var car = BABYLON.MeshBuilder.CreateBox("car", {width : 0.2, height : 0.2, depth : 0.5}, scene);
    car.position = new BABYLON.Vector3(0,4.1,0);
    var transform = new BABYLON.TransformNode("root"); 
    transform.position = new BABYLON.Vector3(0,0,0);
    car.parent = transform;
    scene.registerBeforeRender(function (){
        console.log(car.position)
        transform.rotate(new BABYLON.Vector3(1, 0, 0), -0.02, BABYLON.Space.LOCAL);
    })

I think I’m doing it wrong, because I always have the same position of the car https://playground.babylonjs.com/#68FUS9#1

You need to check car.absolutePosition (in world space) cause locally the car is always at 0 0 0 in the parent node. The previous solution would work too but the second is more flexible as you can also rotate the car around Y for its direction and so on.