New answers tagged 2d-physics
1
Since I researched this in the past, I will post some code I had converted previously that may help you. This is basically the bare minimum of what you can do to achieve this effect. You will most likely want to add damping, and effects such as braking etc. It also works on a system where you only have two tires, one in front and one in back.
The code ...
0
Thanks to the contributors who answered this.
I went with my own solution in the end because it was simply enough to implement and gave perfect results.
All I had to do to scale the acceleration, was the following:
float fallAccel=(dt * num); //Where num is any arbitary amount and dt is the delta time between frames (hence it is scaled and also ...
3
Part of the problem is that your notion of 'velocity' isn't physical. Your updating of position is fine:
spriteYReal = spriteYReal + (spriteYVel * dt);
sprite.yScreen=(int) (spriteYReal*r.height);
This just says that the sprite's position is computed as Pnew = Pold+V*dt, which is fine - it means that V=dP/dt, which is correct. The problem is that the ...
0
Physics update rate must be independent from rendering frame rate. Becase it's not exactly 60 fps.
void update( float dt )
{
float maxStep = 1/60.0f;
if (dt > 0.25)
dt = 0.25f; // note: max frame time to avoid spiral of death
accumulator_ += dt;
while (accumulator_ >= maxStep) {
physical_world_->Step(maxStep);
...
0
Friction
You probably missed friction, in water that is a velocity dependent force working in the opposite direction of the velocity. For light voluminous objects the friction will counteract buoyancy very quickly.
Try pushing a beach-ball either a half or a whole metre under water and let go, you'd think the whole metre would give double the jump height, ...
2
Here's the correct code :
Vector2D weight(mass * gravity);
Vector2D buoyancy(immersedArea * fluidDensity * -gravity);
// assuming operator overloading of +
Vector2D totalForces(weight + buoyancy);
object->applyImpulse(totalForces);
In your code, you calculate mass * area_ratio * gravity but the weight does not depend on the immersed volume ...
0
"current_weight" isn't a function of area_ratio. Weight is just the force of the mass affected by gravity, F=ma or W=mg. The boat will always have the same weight in the direction opposite gravity, but that force is counteracted by buoyancy.
http://www.engineeringtoolbox.com/mass-weight-d_589.html
Try removing area_ratio from your current_weight ...
7
found a detailed breakdown of Mario Physics:
http://forums.mfgg.net/viewtopic.php?p=346301
http://i276.photobucket.com/albums/kk21/jdaster64/smb_playerphysics.png
Top 50 recent answers are included