Adds enemies
This commit is contained in:
parent
cf8ba8bacb
commit
76e5b1927f
324 changed files with 28447 additions and 106 deletions
|
|
@ -11,6 +11,9 @@ func _ready() -> void:
|
|||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED;
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey && event.key_label == KEY_ESCAPE:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
if event is not InputEventMouseMotion:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ static var Instance: Player;
|
|||
|
||||
@onready var animationtree: AnimationTree = $CollisionShape3D/Camera3D/Weapon/AnimationPlayer/AnimationTree
|
||||
@onready var collisionShape: CollisionShape3D = $CollisionShape3D
|
||||
@onready var health: Health = $Health
|
||||
|
||||
const CROUCHED_SPEED: float = 2.5
|
||||
const SPEED: float = 5.0
|
||||
const SPRINT_SPEED: float = 10.0
|
||||
const FALLOFF_SPEED: float = 0.5
|
||||
|
|
@ -54,6 +56,8 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
if PlayerState == PlayerStates.SPRINTING:
|
||||
speed = SPRINT_SPEED
|
||||
if PlayerState == PlayerStates.CROUCHING:
|
||||
speed = CROUCHED_SPEED
|
||||
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
|
|
@ -67,13 +71,16 @@ func _physics_process(delta: float) -> void:
|
|||
if self.PlayerState == PlayerStates.SPRINTING:
|
||||
input_dir.y *= 2
|
||||
|
||||
var blendProperty = 'parameters/Movement/blend_position'
|
||||
var blendProperty = 'parameters/Movement/0/blend_position'
|
||||
if PlayerState == PlayerStates.CROUCHING:
|
||||
blendProperty = 'parameters/Crouched Movement/blend_position'
|
||||
|
||||
lastDirection.x = move_toward(lastDirection.x, input_dir.x, 0.05);
|
||||
lastDirection.y = move_toward(lastDirection.y, input_dir.y, 0.05);
|
||||
animationtree.set(blendProperty, lastDirection);
|
||||
var yLeft = clamp(lastDirection.y - 1, 0, 1);
|
||||
animationtree.set('parameters/Movement/blend_position', yLeft)
|
||||
var yRemainder = Vector2(lastDirection.x, clamp(lastDirection.y, 0, 1));
|
||||
animationtree.set(blendProperty, yRemainder);
|
||||
|
||||
func handleCrouching():
|
||||
if Input.is_action_just_pressed('player_crouching'):
|
||||
|
|
|
|||
|
|
@ -2,13 +2,18 @@ extends Node3D
|
|||
|
||||
@onready var animationtree: AnimationTree = $AnimationPlayer/AnimationTree
|
||||
@onready var timer: Timer = $CooldownTimer
|
||||
|
||||
@export_category("Firing")
|
||||
@export var MuzzleFlash: PackedScene
|
||||
@export var Origin: Node3D
|
||||
@export var BulletOrigin: Node3D
|
||||
|
||||
var statemachine: AnimationNodeStateMachinePlayback
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
self.statemachine = animationtree['parameters/playback']
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is not InputEventMouseButton:
|
||||
return
|
||||
|
|
@ -19,6 +24,9 @@ func _input(event: InputEvent) -> void:
|
|||
if self.timer.time_left > 0:
|
||||
return
|
||||
|
||||
if Player.Instance.PlayerState == Player.PlayerStates.SPRINTING:
|
||||
return
|
||||
|
||||
var travelTarget = 'Fire'
|
||||
if Player.Instance.PlayerState == Player.PlayerStates.CROUCHING:
|
||||
travelTarget = 'Crouched Fire'
|
||||
|
|
@ -26,4 +34,24 @@ func _input(event: InputEvent) -> void:
|
|||
self.animationtree.set('parameters/' + travelTarget + '/blend_position', randf_range(0, 2))
|
||||
self.statemachine.travel(travelTarget)
|
||||
|
||||
fireBullet()
|
||||
|
||||
self.timer.start()
|
||||
|
||||
func fireBullet() -> void:
|
||||
var instance = self.MuzzleFlash.instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE)
|
||||
Origin.add_child(instance)
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.create(BulletOrigin.global_position, BulletOrigin.global_position + BulletOrigin.global_basis.z * -200)
|
||||
var result = get_world_3d().direct_space_state.intersect_ray(query)
|
||||
|
||||
if not result:
|
||||
print('No result')
|
||||
return
|
||||
|
||||
var health = result.collider.get_node('Health')
|
||||
if health:
|
||||
print("Dealing Damage")
|
||||
result.collider.health.take_damage(1, Vector2(0,0))
|
||||
return
|
||||
print('No Health Element')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue