Apply Force Relative To Rotation?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Apply Force Relative To Rotation?

Post by bartbes »

Not 2, most (if not all) keyboards I encountered were able to do at least 3 keys at the same time. (how else would you do ctrl+alt+del, all the windows users need this)
stevec64
Prole
Posts: 1
Joined: Thu Jun 25, 2009 9:36 am

Re: Apply Force Relative To Rotation?

Post by stevec64 »

Alex wrote:Do not use applyForce() or applyImpulse(). They are broken hard. I've reported the bug and sent a patch, but until it goes through, use setVelocity(). It is not broken, and it's possible to model acceleration and jerk using only setVelocity and the time increment.
I just hit this bug recently also... spent a while trying to figure out where unwanted torque was coming from. For the purposes of those who want to make a local fix to their source (I couldn't find Alex's patch on the Tracker):

The offending code is in box2d\Body.cpp. Make the following changes:

Code: Select all

	void Body::applyImpulse(float jx, float jy)
	{
		body->ApplyImpulse(b2Vec2(jx, jy), body->GetWorldCenter());
	}

	void Body::applyImpulse(float jx, float jy, float rx, float ry)
	{
		body->ApplyImpulse(b2Vec2(jx, jy), b2Vec2(rx, ry));
	}

	void Body::applyTorque(float t)
	{
		body->ApplyTorque(t);
	}

	void Body::applyForce(float fx, float fy, float rx, float ry)
	{
		body->ApplyForce(b2Vec2(fx, fy), b2Vec2(rx, ry));
	}

	void Body::applyForce(float fx, float fy)
	{
		body->ApplyForce(b2Vec2(fx, fy), body->GetWorldCenter());
	}

This seemed to fix the issues I had at least, so happily applying forces and impulses now getting the behavior I expect.

Steve
LagMasterSam
Prole
Posts: 8
Joined: Sun Aug 30, 2009 2:24 pm

Re: Apply Force Relative To Rotation?

Post by LagMasterSam »

Alex wrote:Do not use applyForce() or applyImpulse(). They are broken hard. I've reported the bug and sent a patch, but until it goes through, use setVelocity(). It is not broken, and it's possible to model acceleration and jerk using only setVelocity and the time increment.

Aside from that, lejeaunerenard is right. Derive your new x and y using the amount of force you want to apply (R) and the the angle that the object is rotated (theta):

Code: Select all

vx, vy = object:getVelocity()
newX, newY = R*math.cos(theta), R*math.sin(theta)
object:setVelocity(newX + vx, newY + vy)
I've tried using your code. However, my object almost immediately reaches a slow maximum speed, no matter how large I make R.
Post Reply

Who is online

Users browsing this forum: No registered users and 152 guests