- Edited
Hello, I recently got into Godot and now I'm following a bunch of tutorials on how to implement FPS movement. So far I successfully programmed character movement, jumping and gravity (it's not much, but still). After that, I wanted to make a dash mechanic similar to ULTRAKILL - a quick, horizontal dodge. The dash method I have right now actually works well in relation to directions and velocity, but my issue is about the camera. When I dash, it simply teleports from one point to another and I want to make it so it smoothly transitions during the state. I know it's possible to do something with linear_interpolate() or lerp(), but I just can't figure it out.
Here's the function for receiving input weight:
func _get_directions() -> Vector3:
var z: float = ( Input.get_action_strength("backward") - Input.get_action_strength("forward") )
var x: float = ( Input.get_action_strength("right") - Input.get_action_strength("left") )
x_angleLerp = x * -3
return transform.basis.xform(Vector3(x, 0, z)).normalized()
Here's the function for processing movement:
func _physics_process(delta):
if Input.is_action_pressed("ui_cancel"):
get_tree().quit()
input_move = _get_directions()
if Input.is_action_just_pressed("sprint") and can_dash and input_move != Vector3.ZERO:
_dash(input_move, delta) #function for dashing
if not is_on_floor():
gravity_local += Vector3.DOWN * GRAVITY_ACCELERATION * delta
else:
gravity_local = GRAVITY_ACCELERATION * -get_floor_normal() * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
gravity_local = Vector3.UP * JUMP_SPEED
lookPivot.rotation_degrees.z = lerp(lookPivot.rotation_degrees.z, x_angleLerp, 0.1)
move_and_slide((input_move * MAX_SPEED) + gravity_local , Vector3.UP)
And finally, the dash function:
func _dash(input_move, delta):
velocity = velocity.linear_interpolate((input_move * MAX_SPEED) * DASH_SPEED, DASH_ACCELERATION * delta)
move_and_slide(velocity)
can_dash = false
yield(get_tree().create_timer(1.5), "timeout")
can_dash = true
in any case, here's the full code: