Walk velocity interpolation.

remotes/1705382094874458415/tmp_refs/heads/godot4-port
unfa 2020-06-14 21:16:33 +02:00
parent fcfe733ef7
commit 1b00359d81
1 changed files with 18 additions and 4 deletions

View File

@ -6,13 +6,13 @@ const WALK_VELOCITY = 700
const AIR_CONTROL = 0.1
const WALK_ACCEL = 0.1
const WALK_ACCEL = 0.25
const WALK_DECEL = 0.1
const MOUSE_SENSITIVITY = 1.0 / 300
onready var camera = $Camera
onready var debug = get_tree().root.find_node("Debug")
onready var debug = $"../Debug" # really bad
var velocity = Vector3.ZERO
@ -33,8 +33,22 @@ remote func walk(direction: Vector2):
var walkVelocity = WALK_VELOCITY * walkDirectionNormalized
velocity.x = walkVelocity.y
velocity.z = - walkVelocity.x
var interpolation
var currentVelocity = Vector2(- velocity.z, velocity.x)
if walkVelocity.dot(currentVelocity) > 0:
interpolation = WALK_ACCEL
else:
interpolation = WALK_DECEL
debug.text = "Interpolation: " + String(interpolation)
debug.text += "\nwalkVelocity: " + String(walkVelocity)
debug.text += "\ncurrentVelocity: " + String(currentVelocity)
# TODO add air control multiplier for mid-air movement
velocity.x = lerp(velocity.x, walkVelocity.y, interpolation)
velocity.z = lerp(velocity.z, - walkVelocity.x, interpolation)
remote func jump():
print("JUMP")