Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Box 2D setting body to angle.

Author
Message
z i l c h vortex
19
Years of Service
User Offline
Joined: 20th Feb 2007
Location: united kingdom
Posted: 5th Dec 2010 19:20
In box 2D how would i go about setting a body on a certain angle or only allowing a body to rotate between certain angles.

Thank You.

life is short but so am i
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Dec 2010 10:35
"b2SetBodyTransform" but if you use this command the body stops working like a dynamic object should and relies on you telling it where to be positioned and rotated manually. Give it a try you'll see what I mean.

Diggsey will probably spot this and give a more definative answer though!

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 7th Dec 2010 01:34 Edited at: 7th Dec 2010 01:34
"b2SetBodyTransform" is correct. It will only stop the body from reacting to the simulation if you use it every loop (for obvious reasons!)

To restrict rotation, there is no specific joint for it (yet) but you can simulate it using a revolute joint and an extra body.

Create a low density small circular body 'behind' the body you want to restrict, centred on your body's centre of mass (you can get the coordinates of the centre of mass with "b2GetBodyWorldCenterX/Y") and disable rotation on this small body ("b2SetBodyIsRotationFixed").

Then create a revolute joint between the two bodies, again at the centre of mass.

You can enable limits on the revolute joint with "b2SetRevoluteJointIsLimitEnabled" and "b2SetRevoluteJointLimits" to set whatever limits you want.

[b]
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Dec 2010 10:27
Quote: "Create a low density small circular body 'behind' the body you want to restrict, centred on your body's centre of mass (you can get the coordinates of the centre of mass with "b2GetBodyWorldCenterX/Y") and disable rotation on this small body ("b2SetBodyIsRotationFixed").

Then create a revolute joint between the two bodies, again at the centre of mass.

You can enable limits on the revolute joint with "b2SetRevoluteJointIsLimitEnabled" and "b2SetRevoluteJointLimits" to set whatever limits you want"

Ooooh, nice idea. That'll work great for my Heli-bomb!!

z i l c h vortex
19
Years of Service
User Offline
Joined: 20th Feb 2007
Location: united kingdom
Posted: 11th Dec 2010 00:48
That worked perfectly thank you guys !

life is short but so am i

Login to post a reply

Server time is: 2026-07-21 19:18:42
Your offset time is: 2026-07-21 19:18:42