How can I go about rotation based propulsion in a physics environment?

danielfoutz

Member
I'm working on a prototype for a very silly little physics game where you play as a butt and you propel yourself around the stage with your farts. I know, it's very stupid. My problem comes because I want the player to have control over the rotation of the butt and then add an impulse to push them in the direction they are rotated towards.

I've tried using various combinations of physics_apply_local_force, physics_apply_force, physics_apply_impulse, and physics_apply_local_impulse, but I've only been able to either get the character to rotate rapidly or else be pushed in a constant direction rather than one relative to their phy_rotation.

Would anyone be able to give me some tips or else point me in the direction of where I could learn how to apply force relative to rotation direction using box2d physics? It would be much appreciated.

*edit: I attached a picture to try and help demonstrate. The idea is that you control the finger at the top of the hand which is connected to the hand via a revolute joint. The force should come from the butt at the bottom of the hand and propel the player in the rotated direction.
 

Attachments

Last edited:

danielfoutz

Member
Thanks for you reply.

I don't think this will solve my issue though because if I apply torque it will affect the player's rotation, right? I don't want to make the player rotate, I want to push them in the direction that they are already rotated in. Though it's very possible I'm just misunderstanding how to use the function.
 

woods

Member
rotate
if keyboard_check(vk_left) {physics_apply_torque(-100);} // wouldnt this make your "ship" spin to the left(counter-clockwise)?


thrust
if keyboard_check(vk_up) {physics_apply_local_impulse(0, 20, 0, 50);} //wouldnt this make your "ship" move forward?


would be easier to help if we had some code to look at ;o)



fresh project
dropped this into the player step event

GML:
/// movement

//rotate
if keyboard_check(vk_left)
{
physics_apply_torque(-500);
}

if keyboard_check(vk_right)
{
physics_apply_torque(500);
}

//thrust
if keyboard_check(vk_up)
{
physics_apply_local_impulse(0, 20, 0, -50);
}


if keyboard_check(vk_down)
{
physics_apply_local_impulse(0, 20, 0, 50);
}
-- had to adjust the gravity to zero in the room to keep my ship from falling out the bottom.. but other than that default settings on everything

rotation is a bit slow to respond.. but i guess thats how torque works.. keep slowly adding in that direction ;o)
takes a bit to slow down that torque to get it to not spin forever(the longer you spin right...the longer it takes to stop spinning the other direction)
 
Last edited:

FrostyCat

Redemption Seeker
In that case, use lengthdir_x(mag, -phy_rotation) and lengthdir_y(mag, -phy_rotation) for the force vector.
 
Top