You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB
GDScript

2 years ago
extends Node3D
class_name Move
@onready var character = (get_owner() as Character)
@onready var status = (%Status as Status)
@onready var buff = (%Buff as Buff)
2 years ago
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _physics_process(delta):
if status.is_pause:return
2 years ago
update_on_floor(delta)
update_speed_y(delta)
2 years ago
update_move(delta)
2 years ago
character.move_and_slide()
2 years ago
func update_on_floor(delta):
2 years ago
status.is_on_floor = character.is_on_floor()
if status.is_on_floor and not status.is_jumping:
status.is_jumped = false
2 years ago
func update_speed_y(delta):
var has_y_speed = status.skill_float_speed != 0 or status.hit_up_speed != 0
if has_y_speed:
character.velocity.y = status.skill_float_speed + status.hit_up_speed
else:
if not status.is_on_floor:
character.velocity.y -= gravity * delta * status.cfg.move.gravity_scale
2 years ago
status.speed_y = character.velocity.y
2 years ago
func update_move(delta):
var move_velocity = status.move_dir * (status.cfg.move.speed * (1 + status.speed_up_rate))
2 years ago
var skill_velocity = status.skill_dir * status.skill_move_speed
var hit_back_velocity = status.hit_back_dir * status.hit_back_speed
move_velocity += skill_velocity + hit_back_velocity
2 years ago
if move_velocity.length() == 0:
move_velocity = Vector2(character.velocity.x,character.velocity.z);
if status.is_on_floor:
move_velocity = Util.vector_reduce(move_velocity,Setting.drag_ground*delta)
else:
move_velocity = Util.vector_reduce(move_velocity,Setting.drag_air*delta)
else:
move_velocity.x = move_velocity.x
move_velocity.y = move_velocity.y
2 years ago
character.velocity.x = move_velocity.x
character.velocity.z = move_velocity.y
2 years ago
status.speed_xz = Vector2(character.velocity.x,character.velocity.z).length()
if status.is_free_turn and status.move_dir.x != 0:
status.is_right = status.move_dir.x > 0
func jump():
character.velocity.y = status.cfg.move.jump_velocity
status.is_jumped = true
status.trigger_jump = true
buff.add_buff("jumping",0.1)