moving a body

Discuss issues specific the Javascript port of Box2D
monteslu
Posts: 2
Joined: Sun Sep 25, 2011 10:31 am

moving a body

Postby monteslu » Sun Sep 25, 2011 11:06 am

I've found a few references to calling SetXForm() to move a body around, but I can't get this to work with box2dweb

body.SetXForm(new Box2D.Common.Math.b2Vec2( 7,3 , body.GetWorldCenter() ) );

or

body.SetXForm(new Box2D.Common.Math.b2Vec2( 7,3 ) );

Will both throw a TypeError exception.

Anyone have working example of how to do this?

Thanks.

monteslu
Posts: 2
Joined: Sun Sep 25, 2011 10:31 am

Re: moving a body

Postby monteslu » Tue Sep 27, 2011 9:00 pm

well, I've found an extremely hacky workaround:

Box2D.Dynamics.b2World.DestroyBody(aBody);

Then just immediately re-create it somewhere else. Inefficient, but it works.

Would still love to see the proper way to do this.

Architect
Posts: 14
Joined: Mon Feb 20, 2012 2:03 pm

Re: moving a body

Postby Architect » Mon Feb 20, 2012 10:22 pm

You are trying to teleport the player/object right? This works for me.

player.SetPosition (new b2Vec2(x,y) )

It's the box2dweb version btw.


Return to “Javascript”



Who is online

Users browsing this forum: No registered users and 1 guest