Godot Version
4.3-stable
Question
after i tried normalizing my vector to prevent faster diagonal movement i found that my character will just keep moving even when im not touching anything
Heres my code:
var speed = 300.0
var deceleration = 20.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
velocity = velocity.normalized() * speed
# Handle jump.
var directiony := Input.get_axis("up", "down")
if directiony:
velocity.y = directiony * speed
else:
velocity.y = move_toward(velocity.y, 0, deceleration)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var directionx := Input.get_axis("left", "right")
if directionx:
velocity.x = directionx * speed
else:
velocity.x = move_toward(velocity.x, 0, deceleration)
if Input.is_action_just_pressed("run"):
speed += 150.0
else:
move_toward(velocity.x, 0, deceleration)
move_toward(velocity.y, 0, deceleration)
if Input.is_action_just_released("run"):
speed = 300.0
velocity = velocity.normalized() * speed
move_and_slide()
type or paste code here
type or paste code here