Bit more cleanup.
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
@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)
|
158
entities/NPC.gd
158
entities/NPC.gd
@@ -1,158 +0,0 @@
|
||||
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,44 +0,0 @@
|
||||
[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")
|
@@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://2ch34sio36nv"]
|
||||
[gd_scene load_steps=11 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"]
|
||||
[ext_resource type="Script" uid="uid://bdjgvyiacbg28" path="res://entities/player/PlayerCamera.gd" id="5_g3lhm"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2m2ha"]
|
||||
|
||||
@@ -36,6 +37,10 @@ script = ExtResource("4_yjynp")
|
||||
interaction = NodePath("../PlayerInteraction")
|
||||
movement = NodePath("../PlayerMovement")
|
||||
|
||||
[node name="PlayerCamera" type="Node" parent="Scripts" node_paths=PackedStringArray("camera")]
|
||||
script = ExtResource("5_g3lhm")
|
||||
camera = NodePath("../../PlayerCamera")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_2m2ha")
|
||||
|
||||
@@ -53,3 +58,5 @@ 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")
|
||||
|
||||
[node name="PlayerCamera" type="Camera3D" parent="."]
|
6
entities/player/PlayerCamera.gd
Normal file
6
entities/player/PlayerCamera.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
class_name PlayerCamera extends Node
|
||||
|
||||
@export var camera:Camera3D = null
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
1
entities/player/PlayerCamera.gd.uid
Normal file
1
entities/player/PlayerCamera.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bdjgvyiacbg28
|
Reference in New Issue
Block a user