Otimize esse código da Godot Engine: extends CharacterBody2D @export var movespeed = 200…
- User
Otimize esse código da Godot Engine:
extends CharacterBody2D
@export var move_speed = 200 @export var health = 3 @export var gravity = 1200 @export var jump_force = 400 @export var idle_threshold = 10 @export var friction = 20 @export var knockback_intensity = 150000 var hitted = false var can_animate = true var horizontal_direction = 0 var current_enemy = null
func _physics_process(delta): _get_input() velocity.y = velocity.y + gravity * delta velocity.x = lerp(velocity.x, horizontal_direction * move_speed, delta * friction) move_and_slide() _set_animation()
func _get_input(): horizontal_direction = Input.get_axis("move_left", "move_right") if horizontal_direction != 0: $Texture.flip_h = horizontal_direction < 0 if Input.is_action_just_pressed("jump") and _check_ground(): velocity.y = -jump_force
func _check_ground(): for RayCast in $RayCasts.get_children(): if RayCast.is_colliding(): return true return false
func _set_animation(): if can_animate == true: match _check_ground(): true: if velocity.x >= idle_threshold or velocity.x <= -idle_threshold: Animation.play("run") else: Animation.play("jump") else: Animation.play("hit")
- Assistant