![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | ItzKillerTTV |
When starting to implement moving mechanics I realized that my character keeps sliding rapidly even though I specified a friction variable. I’m new to programming in general, so any help would be appreciated. If you need anything else from the code of the project let me know.
Here’s the code:
extends KinematicBody2D
class_name Character, "res://extras/sprite1.png"
const FRICTION = 0.15
export(int) var acceleration: int = 90
export(int) var max_speed: int = 500
onready var animated_sprite: AnimatedSprite = get_node("AnimatedSprite")
var mov_direction: Vector2 = Vector2.ZERO
var velocity: Vector2 = Vector2.ZERO
func _physics_process(_delta: float) -> void:
velocity = move_and_slide(velocity)
velocity = lerp(velocity, Vector2.ZERO, FRICTION)
$AnimatedSprite.play("Idle")
func move() -> void:
mov_direction = mov_direction.normalized()
velocity = mov_direction * acceleration
velocity = velocity.clamped(max_speed)