0

How do I change the position of a body element programatically?

I've tried

body.SetPosition( 0, 0 );

body.SetPosition( { x: 0, y: 0 } );

body.SetPosition( ).x = 0;

body.SetPosition( ).y = 0;

None of the tutorials seem to cover this either - they simply cover how to make an entity and let physics do the rest. I'm trying to manually be able to move the entity, and if needed, give it a new position (e.g teleportation)

Vardan Betikyan
  • 354
  • 5
  • 20
  • 1
    I don't use the javascript port, but have you tried body.setTransform? That's always worked for me - allows you to set the position and the angle of the body. Should be able to achieve "teleportation" that way – Peter R Aug 07 '23 at 13:00
  • Tried `SetTransform( new box2d.b2Vec2( 0, 0 ) );` but it just errors`TypeError: a.GetAngle is not a function`. `SetPosition` kinda works, but it starts ignoring the physics altogether – Vardan Betikyan Aug 08 '23 at 19:43

0 Answers0