I'm trying to implement a boost pad in my XNA game using the Farseer Physics Engine. (This question applies to Box2D too, I would be happy to port working Box2D code to C#.)
By "boost pad", I mean an object that can apply a force to the player that makes him go faster than he usually can under normal circumstances. These are most often seen in non-realistic racing games (e.g., Mario Kart, F-Zero). (For the record, my particular game is a 2D side-scroller.)
I use a very simple Farseer physics Body for my player: it's just a square shape with basic linear velocity.
Normally, I move my player like this:
body.ApplyForce(ConvertUnits.ToSimUnits(force));
Then, in my Update loop method, I cap the player velocity like this (to make sure the player speed never goes above maxSpeed
):
float speed = body.LinearVelocity.Length();
if (speed > maxSpeed)
body.LinearVelocity = (maxSpeed / speed) * velocity;
I'm struggling to think of a good way to implement a boost pad. The issues:
- What would be a good way to enforce two separate max speeds? There's one maximum speed for forces that are applied by normal player input, and another maximum speed for forces applied by boost pads.
- If the character is going faster than the normal max speed (e.g., they just hit a boost pad), how can I still allow the player to influence his direction without increasing his overall speed?