add attacks and death
This commit is contained in:
+5
-2
@@ -29,11 +29,14 @@ extends CharacterBody3D
|
||||
@export_group("Server variables")
|
||||
@export var server_position := Vector3.ZERO
|
||||
@export var server_rotation := Vector3.ZERO
|
||||
@export var player := true
|
||||
@export var dead := false
|
||||
|
||||
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||
@onready var _camera_platform: Node3D = %CameraPlatform
|
||||
@onready var _camera: Node3D = %Camera
|
||||
@onready var rotation_base: Node3D = %RotationBase
|
||||
@onready var collider: Node3D = %Collider
|
||||
|
||||
var camera_input_direction := Vector2.ZERO
|
||||
var last_direction := Vector3.FORWARD
|
||||
@@ -108,9 +111,9 @@ func _on_sync_delta_synchronized() -> void:
|
||||
position = server_position
|
||||
|
||||
|
||||
func apply_input_velocity(delta: float, input_direction: Vector2, speed: float, acceleration: float) -> void:
|
||||
func apply_input_velocity(delta: float, input_direction: Vector2, speed: float, acc: float) -> void:
|
||||
var target_velocity = Vector3(input_direction.x * speed, velocity.y, input_direction.y * speed)
|
||||
velocity = velocity.move_toward(target_velocity, acceleration * delta) + Main.gravity_velocity
|
||||
velocity = velocity.move_toward(target_velocity, acc * delta) + Main.gravity_velocity
|
||||
move_and_slide()
|
||||
|
||||
if input_direction.length() >= 0.1:
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
extends State
|
||||
|
||||
func enter() -> void:
|
||||
super()
|
||||
subject.rotation_base.global_rotation.z = PI / 2
|
||||
subject.collider.disabled = true
|
||||
|
||||
func exit() -> void:
|
||||
super()
|
||||
subject.rotation_base.global_rotation.z = 0
|
||||
subject.collider.disabled = false
|
||||
|
||||
func process_physics(_delta: float) -> State:
|
||||
if not multiplayer.is_server(): return
|
||||
if not subject.dead: return %Idle
|
||||
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@ func process_physics(delta: float) -> State:
|
||||
subject.apply_input_velocity(delta, Vector2.ZERO, 0.0, subject.air_deceleration)
|
||||
|
||||
if not subject.is_on_floor(): return
|
||||
if has_node("%Dead") and subject.dead: return %Dead
|
||||
if %Input.direction.length() < 0.05: return %Idle
|
||||
if has_node("%Walk") and %Input.walk: return %Walk
|
||||
return %Run
|
||||
|
||||
@@ -3,12 +3,12 @@ extends State
|
||||
func process_physics(delta: float) -> State:
|
||||
if not Main.is_server_or_predicting(subject.player_id, subject.client_prediction): return
|
||||
|
||||
var input_direction = %Input.direction
|
||||
subject.apply_input_velocity(delta, Vector2.ZERO, 0.0, subject.acceleration)
|
||||
|
||||
if not subject.is_on_floor(): return %Fall
|
||||
if has_node("%Lunge") and %Input.primary_interact: return %Lunge # TODO: Lunge attacks currently do nothing so Chasers can't move when they click in
|
||||
|
||||
var input_direction = %Input.direction
|
||||
if has_node("%Dead") and subject.dead: return %Dead
|
||||
if has_node("%Lunge") and %Input.primary_interact and (not has_node("%AttackCooldown") or %AttackCooldown.time_left == 0): return %Lunge
|
||||
if input_direction.length() < 0.05: return
|
||||
if has_node("%Walk") and %Input.walk: return %Walk
|
||||
return %Run
|
||||
|
||||
+33
-2
@@ -1,11 +1,42 @@
|
||||
extends State
|
||||
|
||||
var hit = false
|
||||
var players_in_area = {}
|
||||
|
||||
func enter() -> void:
|
||||
super()
|
||||
if has_node("%Attack"): %Attack.visible = true
|
||||
if has_node("%AttackTimer"): %AttackTimer.start()
|
||||
if has_node("%AttackCooldown"): %AttackCooldown.start()
|
||||
hit = false
|
||||
|
||||
func exit() -> void:
|
||||
super()
|
||||
if has_node("%Attack"): %Attack.visible = false
|
||||
|
||||
func process_physics(delta: float) -> State:
|
||||
if not Main.is_server_or_predicting(subject.player_id, subject.client_prediction): return
|
||||
|
||||
var input_direction = %Input.direction if subject.is_on_floor() else Vector2.ZERO
|
||||
|
||||
subject.apply_input_velocity(delta, input_direction, subject.run_speed, subject.acceleration if subject.is_on_floor() else subject.air_deceleration)
|
||||
|
||||
if players_in_area.size() > 0:
|
||||
var hit_player = players_in_area[players_in_area.keys()[0]]
|
||||
hit_player.dead = true
|
||||
hit = true
|
||||
|
||||
if has_node("%AttackTimer") and %AttackTimer.time_left > 0 and not hit: return
|
||||
if not subject.is_on_floor(): return %Fall
|
||||
if input_direction.length() < 0.05: return %Idle
|
||||
if has_node("%Walk") and %Input.walk: return %Walk
|
||||
return
|
||||
return %Run
|
||||
|
||||
func _on_attack_body_entered(body: Node3D) -> void:
|
||||
if body == subject: return
|
||||
if not "player" in body or not body.player: return
|
||||
if body.dead: return
|
||||
|
||||
players_in_area[body.name] = body
|
||||
|
||||
func _on_attack_body_exited(body: Node3D) -> void:
|
||||
players_in_area.erase(body.name)
|
||||
|
||||
@@ -4,10 +4,11 @@ func process_physics(delta: float) -> State:
|
||||
if not Main.is_server_or_predicting(subject.player_id, subject.client_prediction): return
|
||||
|
||||
var input_direction = %Input.direction
|
||||
if input_direction.length() < 0.05: return %Idle
|
||||
|
||||
subject.apply_input_velocity(delta, input_direction, subject.run_speed, subject.acceleration)
|
||||
|
||||
if has_node("%Walk") and %Input.walk: return %Walk
|
||||
if not subject.is_on_floor(): return %Fall
|
||||
if has_node("%Dead") and subject.dead: return %Dead
|
||||
if has_node("%Lunge") and %Input.primary_interact and (not has_node("%AttackCooldown") or %AttackCooldown.time_left == 0): return %Lunge
|
||||
if input_direction.length() < 0.05: return %Idle
|
||||
if has_node("%Walk") and %Input.walk: return %Walk
|
||||
return
|
||||
|
||||
@@ -4,10 +4,11 @@ func process_physics(delta: float) -> State:
|
||||
if not Main.is_server_or_predicting(subject.player_id, subject.client_prediction): return
|
||||
|
||||
var input_direction = %Input.direction
|
||||
if input_direction.length() < 0.05: return %Idle
|
||||
|
||||
subject.apply_input_velocity(delta, input_direction, subject.walk_speed, subject.acceleration)
|
||||
|
||||
if not %Input.walk: return %Run
|
||||
if not subject.is_on_floor(): return %Fall
|
||||
if has_node("%Dead") and subject.dead: return %Dead
|
||||
if has_node("%Lunge") and %Input.primary_interact and (not has_node("%AttackCooldown") or %AttackCooldown.time_left == 0): return %Lunge
|
||||
if input_direction.length() < 0.05: return %Idle
|
||||
if not %Input.walk: return %Run
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user