Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GodotBeginner2023 |
I’m making a top-down 2d game and following a tutorial, but it’s made in version 3 and I’m not sure how to convert the code without disrupting it. I know that clamp requires two arguments, but idk what to use.
extends CharacterBody2D
class_name Character
const FRICTION: float = 0.15
@export var acceleration: int = 40
@export var max_speed: int = 100
var mov_direction: Vector2 = Vector2.ZERO
func _physics_process(_delta: float) -> void:
move_and_slide()
velocity = lerp(velocity, Vector2.ZERO, FRICTION)
func move() -> void:
mov_direction = mov_direction.normalized()
velocity += mov_direction * acceleration
velocity = velocity.clamp(max_speed)