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

@ -33,13 +33,14 @@ 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
GravityJumpAcceleration float64 = 0.05 // gravity while jumping upward (smoother jumps)
SwimGravity float64 = 3 SwimGravity float64 = 3
SwimJumpVelocity float64 = -12 SwimJumpVelocity float64 = -12
SwimJumpCooldown uint64 = 24 // number of frames of cooldown between swim-jumps SwimJumpCooldown uint64 = 24 // number of frames of cooldown between swim-jumps

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