Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set max velocity #92

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/game/components/ship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class Ship extends SpriteComponent
CollisionCallbacks {
static final _random = Random();

Ship(this.player) :
moveJoystick = _makeJoystick(player.gamepadId, leftXAxis, leftYAxis),
Ship(this.player)
: moveJoystick = _makeJoystick(player.gamepadId, leftXAxis, leftYAxis),
super(size: Vector2(40, 80), anchor: Anchor.center) {
paint = Paint()..color = player.color;
spritePath = shipSprites[player.slotNumber];
Expand All @@ -94,6 +94,7 @@ class Ship extends SpriteComponent
double bulletSpeed = 400.0;
double weightFactor = 1.0;
double dragFactor = 5.0;
final double maxVelocity = 1500;

final Vector2 velocity = Vector2.zero();
final Vector2 drag = Vector2.zero();
Expand Down Expand Up @@ -212,7 +213,8 @@ class Ship extends SpriteComponent

_velocityTmp
..setFrom(velocity)
..scale(dt);
..scale(dt)
..clampLength(0, maxVelocity * dt);
_accelerationTmp
..setFrom(acceleration)
..scale(dt2 / 2);
Expand Down