Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dragonwarrior2004 |
extends KinematicBody2D
var MAX_SPEED = 350
var ACCELERATION = 2000
var motion = Vector2.ZERO
var roll_vector = Vector2.LEFT
onready var swordHitbox = $Position2D/Hitbox2
func _ready():
swordHitbox.knockback_vector = roll_vector
func move_state(delta):
var axis = Vector2.ZERO
axis.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
axis.y = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
axis = axis.normalized()
if axis != Vector2.ZERO:
roll_vector = axis
swordHitbox.knockback_vector = axis
func _physics_process(delta):
motion = move_and_slide(motion)
var axis = move_state(delta)
if axis == Vector2.ZERO:
apply_friction(ACCELERATION * delta)
else:
apply_movement(axis * ACCELERATION * delta)
if Input.is_action_just_pressed(“Attack_Down”):
$Fight.play(“Attack_Down”)
elif Input.is_action_just_pressed(“Attack_Up”):
$Fight.play(“Attack_Up”)
elif Input.is_action_just_pressed(“Attack_Left”):
$Fight.play(“Attack_Left”)
elif Input.is_action_just_pressed(“Attack_Right”):
$Fight.play(“Attack_Right”)
func apply_friction(amount):
if motion.length() > amount:
motion -= motion.normalized() * amount
else:
motion = Vector2.ZERO
func apply_movement(acceleration):
motion += acceleration
motion = motion.clamped(MAX_SPEED)