Moving files pre-refactor
This commit is contained in:
15
entities/MapCamera.gd
Normal file
15
entities/MapCamera.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
@tool
|
||||
class_name MapCamera extends Camera3D
|
||||
|
||||
@export var targetFollow:Node3D = null
|
||||
@export var pathFollow:PathFollow3D = null
|
||||
@export var pathMap:Path3D = null
|
||||
|
||||
func _process(delta):
|
||||
if !pathMap || !targetFollow || !pathMap.curve:
|
||||
return
|
||||
|
||||
var point = pathMap.curve.get_closest_point(targetFollow.global_transform.origin)
|
||||
pathFollow.progress_ratio = pathMap.curve.get_closest_offset(point) / pathMap.curve.get_baked_length()
|
||||
global_transform.origin = pathFollow.global_transform.origin
|
||||
look_at(targetFollow.global_transform.origin, Vector3.UP)
|
1
entities/MapCamera.gd.uid
Normal file
1
entities/MapCamera.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://csb0i132lcu0w
|
158
entities/NPC.gd
Normal file
158
entities/NPC.gd
Normal file
@@ -0,0 +1,158 @@
|
||||
class_name NPC extends CharacterBody3D
|
||||
|
||||
const CONVERSATION_FADE_DURATION:float = 0.3
|
||||
|
||||
enum InteractType {
|
||||
NONE,
|
||||
TEXTBOX,
|
||||
CUTSCENE
|
||||
}
|
||||
|
||||
# Movement speed in units per second
|
||||
@export var gravity: float = 24.8
|
||||
|
||||
@export var interactType:InteractType = InteractType.NONE
|
||||
@export_multiline var interactTexts:Array[String] = []
|
||||
@export var npcLookAtPlayer:bool = true
|
||||
@export var playerLookAtNPC:bool = true
|
||||
@export var interactCamera:Camera3D = null
|
||||
@export var cutscene:Cutscene = null
|
||||
|
||||
var nextTextIndex:int = 0
|
||||
var previousCamera:Camera3D = null
|
||||
var playerEnt:Player
|
||||
var conversationEnding:bool = false
|
||||
|
||||
func lookAtPlayer() -> void:
|
||||
if !playerEnt:
|
||||
return
|
||||
|
||||
# Get player position and NPC position
|
||||
var playerPos = playerEnt.global_transform.origin
|
||||
var npcPos = global_transform.origin
|
||||
|
||||
# Rotate the NPC to look at the player
|
||||
if npcLookAtPlayer:
|
||||
var npcDirection = (playerPos - npcPos).normalized()
|
||||
var npcRotation = Vector3(0, atan2(npcDirection.x, npcDirection.z), 0)
|
||||
global_transform.basis = Basis.from_euler(npcRotation)
|
||||
|
||||
# Rotate the player to look at the NPC
|
||||
if playerLookAtNPC:
|
||||
var playerDirection = (npcPos - playerPos).normalized()
|
||||
var playerRotation = Vector3(0, atan2(playerDirection.x, playerDirection.z), 0)
|
||||
playerEnt.global_transform.basis = Basis.from_euler(playerRotation)
|
||||
|
||||
func showTexts():
|
||||
TRANSITION.fadeOutStart.disconnect(showTexts)
|
||||
TRANSITION.fadeInEnd.disconnect(showTexts)
|
||||
|
||||
# Any texts?
|
||||
if interactTexts.size() == 0:
|
||||
endTexts()
|
||||
return
|
||||
|
||||
# First text.
|
||||
UI.TEXTBOX.setText(interactTexts[nextTextIndex])
|
||||
UI.TEXTBOX.textboxClosing.connect(onTextboxClosing)
|
||||
|
||||
func endTexts():
|
||||
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
||||
conversationEnding = true
|
||||
|
||||
# Do we fade out the camera?
|
||||
if interactCamera:
|
||||
TRANSITION.fade(TRANSITION.FadeType.FADE_OUT, CONVERSATION_FADE_DURATION)
|
||||
TRANSITION.fadeOutEnd.connect(onFadeOutEnd)
|
||||
return
|
||||
|
||||
# Reset Camera?
|
||||
if previousCamera:
|
||||
previousCamera.current = true
|
||||
previousCamera = null
|
||||
PAUSE.cutsceneResume()
|
||||
|
||||
func _enter_tree() -> void:
|
||||
$InteractableArea.interactEvent.connect(onInteract)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
$InteractableArea.interactEvent.disconnect(onInteract)
|
||||
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
|
||||
func _physics_process(delta):
|
||||
# Apply gravity if not on floor
|
||||
if !is_on_floor():
|
||||
velocity += PHYSICS.GRAVITY * delta
|
||||
move_and_slide()
|
||||
|
||||
func onInteract(playerEntity:Player) -> void:
|
||||
# Reset state
|
||||
previousCamera = null
|
||||
nextTextIndex = 0
|
||||
playerEnt = playerEntity
|
||||
conversationEnding = false
|
||||
|
||||
match interactType:
|
||||
InteractType.TEXTBOX:
|
||||
PAUSE.cutscenePause()
|
||||
|
||||
# If a camera is set, switch to it, otherwise chat immediately.
|
||||
if interactCamera == null:
|
||||
lookAtPlayer()
|
||||
showTexts()
|
||||
return
|
||||
|
||||
# Fade out.
|
||||
TRANSITION.fade(TRANSITION.FadeType.FADE_OUT, CONVERSATION_FADE_DURATION)
|
||||
TRANSITION.fadeOutEnd.connect(onFadeOutEnd)
|
||||
|
||||
InteractType.CUTSCENE:
|
||||
if !cutscene:
|
||||
return
|
||||
cutscene.start()
|
||||
|
||||
_:
|
||||
return
|
||||
|
||||
func onTextboxClosing() -> void:
|
||||
nextTextIndex += 1
|
||||
|
||||
# More text?
|
||||
if nextTextIndex < interactTexts.size():
|
||||
UI.TEXTBOX.setText(interactTexts[nextTextIndex])
|
||||
else:
|
||||
endTexts()
|
||||
|
||||
func onFadeOutEnd() -> void:
|
||||
# Begin fade back in.
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
TRANSITION.fade(TRANSITION.FadeType.FADE_IN, CONVERSATION_FADE_DURATION)
|
||||
TRANSITION.fadeInEnd.connect(onFadeInEnd)
|
||||
|
||||
# Is the conversation ending?
|
||||
if conversationEnding:
|
||||
# Reset camera.
|
||||
if previousCamera:
|
||||
previousCamera.current = true
|
||||
previousCamera = null
|
||||
return
|
||||
|
||||
# No! We are starting the conversation, make the ents look at each other
|
||||
lookAtPlayer()
|
||||
|
||||
# Change camera
|
||||
previousCamera = get_viewport().get_camera_3d()
|
||||
interactCamera.current = true
|
||||
|
||||
func onFadeInEnd() -> void:
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
|
||||
# Did the conversation end?
|
||||
if conversationEnding:
|
||||
PAUSE.cutsceneResume()
|
||||
return
|
||||
|
||||
# Show texts after fade in.
|
||||
showTexts()
|
1
entities/NPC.gd.uid
Normal file
1
entities/NPC.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jbarxyoib5a7
|
44
entities/NPC.tscn
Normal file
44
entities/NPC.tscn
Normal file
@@ -0,0 +1,44 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://bng2mc7fu5aik"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jbarxyoib5a7" path="res://entities/NPC.gd" id="1_nnu5p"]
|
||||
[ext_resource type="Script" uid="uid://b00rxpveu3v4m" path="res://InteractableArea.gd" id="2_mm6je"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2m2ha"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_g13of"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nnu5p"]
|
||||
albedo_color = Color(0.389287, 0.389287, 0.389287, 1)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_g13of"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_g13of"]
|
||||
albedo_color = Color(0.596173, 0.00177814, 0.790136, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_mm6je"]
|
||||
size = Vector3(0.958008, 0.97168, 0.767578)
|
||||
|
||||
[node name="NPC" type="CharacterBody3D"]
|
||||
script = ExtResource("1_nnu5p")
|
||||
metadata/_custom_type_script = "uid://jbarxyoib5a7"
|
||||
|
||||
[node name="Scripts" type="Node" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_2m2ha")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CapsuleMesh_g13of")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_nnu5p")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(0.598863, 0, 0, 0, 0.598863, 0, 0, 0, 0.598863, 0, 0.441532, 0.539694)
|
||||
mesh = SubResource("BoxMesh_g13of")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_g13of")
|
||||
|
||||
[node name="InteractableArea" type="Area3D" parent="."]
|
||||
script = ExtResource("2_mm6je")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractableArea"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0152938, 0.00782323, 0.0022831)
|
||||
shape = SubResource("BoxShape3D_mm6je")
|
0
entities/Player.gd
Normal file
0
entities/Player.gd
Normal file
1
entities/Player.gd.uid
Normal file
1
entities/Player.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c0by5m1upv57h
|
55
entities/Player.tscn
Normal file
55
entities/Player.tscn
Normal file
@@ -0,0 +1,55 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://2ch34sio36nv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ylmy3nvpirgr" path="res://entities/player/Player.gd" id="1_24gqh"]
|
||||
[ext_resource type="Script" uid="uid://bwxdv3kxrs4oj" path="res://entities/player/PlayerMovement.gd" id="2_o7et6"]
|
||||
[ext_resource type="Script" uid="uid://b3nty7pvbo58d" path="res://entities/player/PlayerInteraction.gd" id="3_24gqh"]
|
||||
[ext_resource type="Script" uid="uid://bdv1fj1pwknrs" path="res://entities/player/PlayerInput.gd" id="4_yjynp"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2m2ha"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_g13of"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_g13of"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_g13of"]
|
||||
albedo_color = Color(0.0156863, 0.282353, 1, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
|
||||
size = Vector3(0.705444, 0.680542, 1.17688)
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
script = ExtResource("1_24gqh")
|
||||
|
||||
[node name="Scripts" type="Node" parent="."]
|
||||
|
||||
[node name="PlayerMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("player")]
|
||||
script = ExtResource("2_o7et6")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="PlayerInteraction" type="Node" parent="Scripts" node_paths=PackedStringArray("interactableArea", "player")]
|
||||
script = ExtResource("3_24gqh")
|
||||
interactableArea = NodePath("../../PlayerInteractableArea")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="PlayerInput" type="Node" parent="Scripts" node_paths=PackedStringArray("interaction", "movement")]
|
||||
script = ExtResource("4_yjynp")
|
||||
interaction = NodePath("../PlayerInteraction")
|
||||
movement = NodePath("../PlayerMovement")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_2m2ha")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CapsuleMesh_g13of")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(0.598863, 0, 0, 0, 0.598863, 0, 0, 0, 0.598863, 0, 0.441532, 0.539694)
|
||||
mesh = SubResource("BoxMesh_g13of")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_g13of")
|
||||
|
||||
[node name="PlayerInteractableArea" type="Area3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.185831, 0.817421)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerInteractableArea"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0123757, 0.0497631, 0.0865124)
|
||||
shape = SubResource("BoxShape3D_g13of")
|
1
entities/player/Player.gd
Normal file
1
entities/player/Player.gd
Normal file
@@ -0,0 +1 @@
|
||||
class_name Player extends CharacterBody3D
|
1
entities/player/Player.gd.uid
Normal file
1
entities/player/Player.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ylmy3nvpirgr
|
13
entities/player/PlayerInput.gd
Normal file
13
entities/player/PlayerInput.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
class_name PlayerInput extends Node
|
||||
|
||||
@export var interaction:PlayerInteraction
|
||||
@export var movement:PlayerMovement
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("pause"):
|
||||
PAUSE.menuPause()
|
||||
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
interaction.interact()
|
||||
|
||||
movement.inputDir = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()
|
1
entities/player/PlayerInput.gd.uid
Normal file
1
entities/player/PlayerInput.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bdv1fj1pwknrs
|
27
entities/player/PlayerInteraction.gd
Normal file
27
entities/player/PlayerInteraction.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
class_name PlayerInteraction extends Node
|
||||
|
||||
@export var interactableArea:Area3D
|
||||
@export var player:CharacterBody3D
|
||||
|
||||
func canInteract() -> bool:
|
||||
if PAUSE.isMovementPaused():
|
||||
return false
|
||||
return true
|
||||
|
||||
func interact() -> void:
|
||||
if !canInteract():
|
||||
return
|
||||
|
||||
var overlapping = interactableArea.get_overlapping_areas()
|
||||
var interactable: InteractableArea = null
|
||||
|
||||
for node in overlapping:
|
||||
if !(node is InteractableArea):
|
||||
continue
|
||||
interactable = node
|
||||
break
|
||||
|
||||
if !interactable:
|
||||
return
|
||||
|
||||
interactable.interactEvent.emit(player)
|
1
entities/player/PlayerInteraction.gd.uid
Normal file
1
entities/player/PlayerInteraction.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b3nty7pvbo58d
|
47
entities/player/PlayerMovement.gd
Normal file
47
entities/player/PlayerMovement.gd
Normal file
@@ -0,0 +1,47 @@
|
||||
class_name PlayerMovement extends Node
|
||||
|
||||
const TURN_SPEED = 30.0
|
||||
const SPEED = 8.0
|
||||
|
||||
@export var player:CharacterBody3D
|
||||
var inputDir:Vector2 = Vector2.ZERO
|
||||
|
||||
func canMove() -> bool:
|
||||
if PAUSE.isMovementPaused():
|
||||
return false
|
||||
return true
|
||||
|
||||
func _physics_process(delta:float) -> void:
|
||||
var cameraCurrent = get_viewport().get_camera_3d()
|
||||
if !cameraCurrent:
|
||||
return
|
||||
|
||||
# Player movement
|
||||
var directionAdjusted = Vector3.ZERO
|
||||
if canMove():
|
||||
# Use camera orientation for movement direction
|
||||
var cam_basis = cameraCurrent.global_transform.basis
|
||||
# Forward and right vectors, ignore vertical component
|
||||
var forward = -cam_basis.z
|
||||
forward.y = 0
|
||||
forward = forward.normalized()
|
||||
var right = cam_basis.x
|
||||
right.y = 0
|
||||
right = right.normalized()
|
||||
directionAdjusted = (forward * inputDir.y + right * inputDir.x).normalized()
|
||||
|
||||
# Rotate player to face movement direction if moving
|
||||
if directionAdjusted.length() > 0.01:
|
||||
var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
|
||||
player.rotation.y = lerp_angle(
|
||||
player.rotation.y, targetRot, TURN_SPEED * delta
|
||||
)
|
||||
|
||||
# Apply gravity if not on floor
|
||||
if !player.is_on_floor():
|
||||
player.velocity += PHYSICS.GRAVITY * delta
|
||||
|
||||
# Set velocity and move
|
||||
player.velocity.x = directionAdjusted.x * SPEED
|
||||
player.velocity.z = directionAdjusted.z * SPEED
|
||||
player.move_and_slide()
|
1
entities/player/PlayerMovement.gd.uid
Normal file
1
entities/player/PlayerMovement.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bwxdv3kxrs4oj
|
Reference in New Issue
Block a user