2D Movement and Speed-boosters/Currents

Started by
0 comments, last by Thaumaturge 2 years, 7 months ago

In short:

How do 2D, top-down games usually handle things like speed-boosts or speed-affecting currents?

To explain:

I'm working on a 2D, top-down game at the moment. As things stand, movement works more or less as follows:

  • Each character (player or NPC) has a velocity-vector
  • When moving under their own power, a character is marked as “walking”
  • While walking, they have a set maximum speed
  • While not walking, friction is applied to bring them to a stop

And I'm overall happy with the way that this works.

However, I find myself wanting to implement things like “currents” that push strongly against characters within them, and that allow for faster movement than the character would normally be allowed. The sort of thing that one might find in an underwater region, or perhaps a racing game.

But this doesn't really fit into the above system: the player should still have some control (albeit that they're pushed by the current), but should have a higher-than-walking maximum speed.

Now, I've considered a few options--but thus far none have seemed likely to work. Here are my thoughts at time of writing:

  • I could apply a temporary increase to the character's maximum speed, while applying a constant force to them.
    • This should work
    • However:
      • It would I think, allow the character higher-than-walking speed in a direction other than that of the current's force, which doesn't match what I'm going for.
      • And there's the question of what happens when the character exits the “current”:
        • If their maximum speed immediately resets, then the speed-boost exists only within the current, which doesn't feel ideal.
        • Conversely, if it doesn't immediately reset, then the character would be able to move in any direction at higher-than-walking speed, which really doesn't match what I'm going for.
  • I could have separate “personal” and “extraneous” speeds.
    • These would then be added in each frame to produce a total speed
    • The "personal" speed would retain the current rules for friction, while the "extraneous" speed would have constant friction applied.
    • Within a “current”, this should produce the sort of movement that I'm looking for.
    • However once the player exits a "current" (or is subject to knockback), they would find that moving counter to their "extraneous" speed would reduce their total speed as expected--until they stopped, at which point their total speed might well increase as the "personal" speed vanishes but the "extraneous" speed doesn't!
  • I could rework my movement system to centre around applied forces and drag-forces, the latter being proportional to speed.
    • This is the most true of this list to the physics of our world, I believe
    • However, it also removes a layer of abstraction, and in doing so makes it harder to model expected player-intentions in movement.
      • After all, when one stops walking, one doesn't glide slowly to a halt due to drag-forces! So, a counter-force on stopping would seem to be called for.
      • But conversely, when one stops moving relative to a current, one may well make no attempt to cease movement, but allow oneself to be carried--and hence no counter-force would be called for.

[edit]

One more approach has occurred to me, which may allow me to at least have currents/speed-boosts, albeit without providing a more-general solution:

  • I could have whatever object handles the “currents”/speed-boosts keep a record of all objects within it, and an independent velocity for each of those objects. This would then be used to move those objects on each frame (separately from the standard object-movement), providing the desired extra speed. When an object exits the “current”/speed-boost, that separate velocity would be applied to the object's internal velocity, allowing for some degree of continuity.

[/edit]

So, I return to my question: How has this been handled in other games?

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement