Apply Force Relative To Rotation?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Apply Force Relative To Rotation?
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)
Re: Apply Force Relative To Rotation?
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):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.
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());
}
Steve
-
- Prole
- Posts: 8
- Joined: Sun Aug 30, 2009 2:24 pm
Re: Apply Force Relative To Rotation?
I've tried using your code. However, my object almost immediately reaches a slow maximum speed, no matter how large I make R.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)
Who is online
Users browsing this forum: No registered users and 152 guests