JeremyLeland / SectorC37

A top-down space shooting game
0 stars 0 forks source link

Change player speed with mouse target distance #4

Closed JeremyLeland closed 3 years ago

JeremyLeland commented 3 years ago

Speed up if cursor is far away, slow down if cursor is near player? See how this feels.

JeremyLeland commented 3 years ago

The code that did this was:

final mouseDist = sqrt(pow(mouse.x + scrollX - player.x, 2) + pow(mouse.y + scrollY - player.y, 2)); const SPEED_MULTIPLIER = 0.002; player.speed = min(mouseDist * SPEED_MULTIPLIER, Player.MAX_SPEED);

However, this is awkward if you are also trying to shoot -- the tendency is to put the crosshair over what you are aiming for, which can dramatically throw off your speed.

Not sure if having variable speeds is worth the trouble. You could control it with the scroll wheel, maybe, but that may not be intuitive either. Might be better to have "afterburner"/sprint with a key press.