AI part 5
parent
1d204d1c6c
commit
3beac6a586
File diff suppressed because one or more lines are too long
@ -1,52 +0,0 @@
|
|||||||
extends CharacterBody3D
|
|
||||||
|
|
||||||
@onready var anim_tree := $AnimationTree
|
|
||||||
@onready var anim_state = $AnimationTree.get("parameters/playback")
|
|
||||||
@onready var spring_arm: SpringArm3D = $SpringArm3D
|
|
||||||
@onready var model := $Root
|
|
||||||
|
|
||||||
var jumping := false
|
|
||||||
var mouse_sensitivity := 0.006
|
|
||||||
var rotation_speed := 24.0
|
|
||||||
var lerp_val := 0.1
|
|
||||||
|
|
||||||
const SPEED = 5.0
|
|
||||||
const JUMP_VELOCITY = 4.5
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
|
||||||
# Move camera
|
|
||||||
if event is InputEventMouseMotion:
|
|
||||||
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.y -= event.relative.x * mouse_sensitivity
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
|
||||||
# Add the gravity.
|
|
||||||
if not is_on_floor():
|
|
||||||
velocity += get_gravity() * delta
|
|
||||||
jumping = !is_on_floor()
|
|
||||||
|
|
||||||
# Get the input direction and handle the movement/deceleration.
|
|
||||||
var input = Input.get_vector("left", "right", "forward", "back")
|
|
||||||
var direction = Vector3(input.x, 0, input.y).rotated(Vector3.UP, spring_arm.rotation.y)
|
|
||||||
if direction:
|
|
||||||
if not jumping:
|
|
||||||
anim_state.travel("run")
|
|
||||||
velocity.x = lerp(velocity.x, direction.x * SPEED, lerp_val)
|
|
||||||
velocity.z = lerp(velocity.z, direction.z * SPEED, lerp_val)
|
|
||||||
else:
|
|
||||||
anim_state.travel("idle")
|
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
||||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
|
||||||
if velocity.length() > 1.0:
|
|
||||||
model.rotation.y = lerp_angle(model.rotation.y, spring_arm.rotation.y, rotation_speed * delta)
|
|
||||||
|
|
||||||
# Handle jump.
|
|
||||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
|
||||||
velocity.y = JUMP_VELOCITY
|
|
||||||
jumping = true
|
|
||||||
|
|
||||||
anim_tree.set("parameters/conditions/jumping", jumping)
|
|
||||||
anim_tree.set("parameters/conditions/grounded", not jumping)
|
|
||||||
|
|
||||||
move_and_slide()
|
|
||||||
@ -1 +0,0 @@
|
|||||||
uid://cqwweorvt4hbi
|
|
||||||
@ -1,16 +1,29 @@
|
|||||||
class_name Target extends RigidBody3D
|
class_name Target
|
||||||
var health: int = 10
|
extends RigidBody3D
|
||||||
|
|
||||||
signal damaged(amount)
|
const MAX_HEALTH: int = 10
|
||||||
|
var current_health: int = MAX_HEALTH
|
||||||
|
signal damaged(amount: int)
|
||||||
signal died()
|
signal died()
|
||||||
|
|
||||||
func take_damage(damage_amount: int) -> void:
|
|
||||||
health -= damage_amount
|
func is_dead() -> bool:
|
||||||
emit_signal("damaged", damage_amount)
|
return current_health <= 0
|
||||||
if health <= 0:
|
|
||||||
|
|
||||||
|
func take_damage(amount: int) -> void:
|
||||||
|
if amount <= 0:
|
||||||
|
return
|
||||||
|
if is_dead():
|
||||||
|
return
|
||||||
|
var was_alive := not is_dead()
|
||||||
|
current_health = max(0, current_health - amount)
|
||||||
|
emit_signal("damaged", amount)
|
||||||
|
if was_alive and is_dead():
|
||||||
emit_signal("died")
|
emit_signal("died")
|
||||||
die()
|
die()
|
||||||
|
|
||||||
|
|
||||||
func die() -> void:
|
func die() -> void:
|
||||||
# Optional: spawn explosion, play animation/sound, then remove
|
# Optional: Explosion/Animation/Sound abspielen, dann entfernen
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|||||||
@ -1,24 +1,32 @@
|
|||||||
class_name WallDoorway extends ItemInteractable
|
class_name WallDoorway
|
||||||
|
extends ItemInteractable
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
state_changed.connect(_on_state_changed)
|
state_changed.connect(_on_state_changed)
|
||||||
interaction_area.interact = Callable(self, "_on_interact")
|
interaction_area.interact = Callable(self, "_on_interact")
|
||||||
state = States.closed
|
apply_state(States.closed)
|
||||||
|
|
||||||
|
|
||||||
func _on_interact() -> void:
|
func _on_interact() -> void:
|
||||||
match state:
|
apply_state(_toggled_state(state))
|
||||||
States.closed:
|
|
||||||
animation_player.play("open")
|
|
||||||
#recalculate_navigation_map.emit(self)
|
|
||||||
state = States.opened
|
|
||||||
States.opened:
|
|
||||||
animation_player.play("close")
|
|
||||||
#recalculate_navigation_map.emit(self)
|
|
||||||
state = States.closed
|
|
||||||
|
|
||||||
func _on_state_changed(new_state: States) -> void:
|
func _on_state_changed(new_state: States) -> void:
|
||||||
match new_state:
|
_update_action_name(new_state)
|
||||||
States.closed:
|
|
||||||
interaction_area.action_name = "open door"
|
|
||||||
States.opened:
|
func apply_state(new_state: States) -> void:
|
||||||
interaction_area.action_name = "close door"
|
if new_state == States.closed:
|
||||||
|
animation_player.play(ANIM_CLOSE)
|
||||||
|
else:
|
||||||
|
animation_player.play(ANIM_OPEN)
|
||||||
|
state = new_state
|
||||||
|
_update_action_name(new_state)
|
||||||
|
|
||||||
|
|
||||||
|
func _toggled_state(s: States) -> States:
|
||||||
|
return States.opened if s == States.closed else States.closed
|
||||||
|
|
||||||
|
|
||||||
|
func _update_action_name(s: States) -> void:
|
||||||
|
interaction_area.action_name = ACTION_OPEN if s == States.closed else ACTION_CLOSE
|
||||||
|
|||||||
Loading…
Reference in New Issue