|
|
|
@ -11,6 +11,7 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|
|
|
var jumping := false
|
|
|
|
var jumping := false
|
|
|
|
var attacks := ["1h_slice_diagonal","1h_slice_horizontal","1h_attack_chop"]
|
|
|
|
var attacks := ["1h_slice_diagonal","1h_slice_horizontal","1h_attack_chop"]
|
|
|
|
var last_floor := true
|
|
|
|
var last_floor := true
|
|
|
|
|
|
|
|
var blocking := false
|
|
|
|
|
|
|
|
|
|
|
|
@onready var spring_arm := $SpringArm3D
|
|
|
|
@onready var spring_arm := $SpringArm3D
|
|
|
|
@onready var model := $Rig
|
|
|
|
@onready var model := $Rig
|
|
|
|
@ -25,32 +26,47 @@ func _physics_process(delta: float) -> void:
|
|
|
|
model.rotation.y = lerp_angle(model.rotation.y, spring_arm.rotation.y, rotation_speed * delta)
|
|
|
|
model.rotation.y = lerp_angle(model.rotation.y, spring_arm.rotation.y, rotation_speed * delta)
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
|
|
|
|
#move camera
|
|
|
|
if event is InputEventMouseMotion:
|
|
|
|
if event is InputEventMouseMotion:
|
|
|
|
spring_arm.rotation.x -= event.relative.y * mouse_sensitivity
|
|
|
|
spring_arm.rotation.x -= event.relative.y * mouse_sensitivity
|
|
|
|
spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90.0, 30.0)
|
|
|
|
spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90.0, 30.0)
|
|
|
|
spring_arm.rotation.y -= event.relative.x * mouse_sensitivity
|
|
|
|
spring_arm.rotation.y -= event.relative.x * mouse_sensitivity
|
|
|
|
|
|
|
|
#attack
|
|
|
|
if event.is_action_pressed("attack"):
|
|
|
|
if event.is_action_pressed("attack"):
|
|
|
|
anim_state.travel(attacks.pick_random())
|
|
|
|
if blocking:
|
|
|
|
|
|
|
|
anim_state.travel("Block_Attack")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
anim_state.travel(attacks.pick_random())
|
|
|
|
|
|
|
|
#block
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("block"):
|
|
|
|
|
|
|
|
blocking = true
|
|
|
|
|
|
|
|
if Input.is_action_just_released("block"):
|
|
|
|
|
|
|
|
blocking = false
|
|
|
|
|
|
|
|
anim_tree.set("parameters/conditions/blocking", blocking)
|
|
|
|
|
|
|
|
anim_tree.set("parameters/conditions/not_blocking", !blocking)
|
|
|
|
|
|
|
|
#jump
|
|
|
|
if is_on_floor() and Input.is_action_just_pressed("jump"):
|
|
|
|
if is_on_floor() and Input.is_action_just_pressed("jump"):
|
|
|
|
velocity.y = jump_speed
|
|
|
|
velocity.y = jump_speed
|
|
|
|
jumping = true
|
|
|
|
jumping = true
|
|
|
|
anim_tree.set("parameters/conditions/grounded", false)
|
|
|
|
anim_tree.set("parameters/conditions/grounded", false)
|
|
|
|
anim_tree.set("parameters/conditions/jumping", jumping)
|
|
|
|
|
|
|
|
# We just hit the floor after being in the air
|
|
|
|
# We just hit the floor after being in the air
|
|
|
|
if is_on_floor() and not last_floor:
|
|
|
|
if is_on_floor() and not last_floor:
|
|
|
|
jumping = false
|
|
|
|
jumping = false
|
|
|
|
anim_tree.set("parameters/conditions/grounded", true)
|
|
|
|
anim_tree.set("parameters/conditions/grounded", true)
|
|
|
|
last_floor = is_on_floor()
|
|
|
|
|
|
|
|
# We're in the air, but we didn't jump
|
|
|
|
# We're in the air, but we didn't jump
|
|
|
|
if not is_on_floor() and not jumping:
|
|
|
|
if not is_on_floor() and not jumping:
|
|
|
|
anim_state.travel("Jump_Idle")
|
|
|
|
anim_state.travel("Jump_Idle")
|
|
|
|
anim_tree.set("parameters/conditions/grounded", false)
|
|
|
|
anim_tree.set("parameters/conditions/grounded", false)
|
|
|
|
|
|
|
|
anim_tree.set("parameters/conditions/jumping", jumping)
|
|
|
|
|
|
|
|
last_floor = is_on_floor()
|
|
|
|
|
|
|
|
|
|
|
|
func get_move_input(delta: float) -> void:
|
|
|
|
func get_move_input(delta: float) -> void:
|
|
|
|
var vy = velocity.y
|
|
|
|
var vy = velocity.y
|
|
|
|
velocity.y = 0
|
|
|
|
velocity.y = 0
|
|
|
|
var input = Input.get_vector("left", "right", "forward", "back")
|
|
|
|
var input = Input.get_vector("left", "right", "forward", "back")
|
|
|
|
var dir = Vector3(input.x, 0, input.y).rotated(Vector3.UP, spring_arm.rotation.y)
|
|
|
|
var dir = Vector3(input.x, 0, input.y).rotated(Vector3.UP, spring_arm.rotation.y)
|
|
|
|
|
|
|
|
if blocking:
|
|
|
|
|
|
|
|
dir = Vector3.ZERO
|
|
|
|
velocity = lerp(velocity, dir * speed, acceleration * delta)
|
|
|
|
velocity = lerp(velocity, dir * speed, acceleration * delta)
|
|
|
|
var vl = velocity * model.transform.basis
|
|
|
|
var vl = velocity * model.transform.basis
|
|
|
|
anim_tree.set("parameters/IWR/blend_position", Vector2(vl.x, -vl.z) / speed)
|
|
|
|
anim_tree.set("parameters/IWR/blend_position", Vector2(vl.x, -vl.z) / speed)
|
|
|
|
|