jrouwe / JoltPhysics.js

Port of JoltPhysics to JavaScript using emscripten
MIT License
274 stars 21 forks source link

Changing The Objects Positions #186

Closed AntoineUserName closed 4 months ago

AntoineUserName commented 4 months ago

Hello, I need to edit sometimes the position of some objects, I can get the position with the GetPosition() function but I cannot edit the position.

    let pos;

    // Do nothing:
    pos = body.GetPosition();
    pos.SetY(8);

    // Do nothing:
    pos = body.GetWorldTransform().GetTranslation();
    pos.SetY(8);
    body.GetWorldTransform().SetTranslation(pos);

Note: In this example the variable body have the type Jolt.EMotionType_Dynamic.

jrouwe commented 4 months ago

body.GetPosition / body.GetWorldTransform returns a copy of the position. Adjusting it doesn't have any effect other than modifying the copy.

You should use BodyInterface.SetPosition to update the position of a body.