Tweak gravity and player physics

This commit is contained in:
Noah 2024-02-06 19:04:47 -08:00
parent 6fc5900131
commit 8216e5863b
2 changed files with 24 additions and 14 deletions

View File

@ -32,18 +32,19 @@ var (
} }
// Player speeds // Player speeds
PlayerMaxVelocity float64 = 7 PlayerMaxVelocity float64 = 7
PlayerJumpVelocity float64 = -23 PlayerJumpVelocity float64 = -15
PlayerAcceleration float64 = 0.04 // 0.12 PlayerAcceleration float64 = 0.04 // 0.12
PlayerFriction float64 = 0.1 PlayerFriction float64 = 0.1
SlipperyAcceleration float64 = 0.02 SlipperyAcceleration float64 = 0.02
SlipperyFriction float64 = 0.02 SlipperyFriction float64 = 0.02
Gravity float64 = 7 GravityMaximum float64 = 7 // max pull of gravity
GravityAcceleration float64 = 0.1 GravityAcceleration float64 = 0.25 // normal gravity acceleration downward
SwimGravity float64 = 3 GravityJumpAcceleration float64 = 0.05 // gravity while jumping upward (smoother jumps)
SwimJumpVelocity float64 = -12 SwimGravity float64 = 3
SwimJumpCooldown uint64 = 24 // number of frames of cooldown between swim-jumps SwimJumpVelocity float64 = -12
SlopeMaxHeight = 8 // max pixel height for player to walk up a slope SwimJumpCooldown uint64 = 24 // number of frames of cooldown between swim-jumps
SlopeMaxHeight = 8 // max pixel height for player to walk up a slope
// Number of game ticks to insist the canvas follows the player at the start // Number of game ticks to insist the canvas follows the player at the start
// of a level - to overcome Anvils settling into their starting positions so // of a level - to overcome Anvils settling into their starting positions so

View File

@ -73,14 +73,23 @@ func (w *Canvas) loopActorCollision() error {
// Apply gravity to the actor's velocity. // Apply gravity to the actor's velocity.
if a.hasGravity && !a.Grounded() { //v.Y >= 0 { if a.hasGravity && !a.Grounded() { //v.Y >= 0 {
if !a.Grounded() { if !a.Grounded() {
var gravity = balance.Gravity var (
gravity = balance.GravityMaximum
acceleration = balance.GravityAcceleration
)
if a.IsWet() { if a.IsWet() {
gravity = balance.SwimGravity gravity = balance.SwimGravity
} }
// If the actor is jumping/moving upwards, apply softer gravity.
if v.Y < 0 {
acceleration = balance.GravityJumpAcceleration
}
v.Y = physics.Lerp( v.Y = physics.Lerp(
v.Y, // current speed v.Y, // current speed
gravity, // target max gravity falling downwards gravity, // target max gravity falling downwards
balance.GravityAcceleration, acceleration,
) )
} else { } else {
v.Y = 0 v.Y = 0