Whatever lol
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
uid://b00rxpveu3v4m
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://cpqmjomfpyifw
|
|
||||||
1
_archive/InteractableArea.gd.uid
Normal file
1
_archive/InteractableArea.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cql02fqctrd4r
|
||||||
1
_archive/MapChangeInteract.gd.uid
Normal file
1
_archive/MapChangeInteract.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dgev713uv0kdk
|
||||||
85
_archive/entity/EntityMovement.gd
Normal file
85
_archive/entity/EntityMovement.gd
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# @tool
|
||||||
|
# class_name EntityMovement extends Node
|
||||||
|
|
||||||
|
# const FRICTION = 0.01
|
||||||
|
# const WALK_SPEED_DEFAULT = 8
|
||||||
|
# const RUN_SPEED_DEFAULT = 12
|
||||||
|
|
||||||
|
# var _inputDir:Vector2 = Vector2.ZERO
|
||||||
|
# var _running:bool = false
|
||||||
|
|
||||||
|
# @export var body:CharacterBody3D
|
||||||
|
# @export var rotate:Node3D
|
||||||
|
# @export var walkSpeed:float = WALK_SPEED_DEFAULT
|
||||||
|
# @export var runSpeed:float = RUN_SPEED_DEFAULT
|
||||||
|
|
||||||
|
# #
|
||||||
|
# # Private Methods
|
||||||
|
# #
|
||||||
|
# func _applyGravity() -> void:
|
||||||
|
# if !body.is_on_floor():
|
||||||
|
# body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||||
|
|
||||||
|
# func _applyMovement() -> void:
|
||||||
|
# if !canMove():
|
||||||
|
# return
|
||||||
|
|
||||||
|
# var cameraCurrent = get_viewport().get_camera_3d()
|
||||||
|
# if !cameraCurrent:
|
||||||
|
# return
|
||||||
|
|
||||||
|
# # Use camera orientation for movement direction
|
||||||
|
# var camBasis = cameraCurrent.global_transform.basis
|
||||||
|
|
||||||
|
# # Forward and right vectors, ignore vertical component
|
||||||
|
# var forward = -camBasis.z
|
||||||
|
# forward.y = 0
|
||||||
|
# forward = forward.normalized()
|
||||||
|
# var right = camBasis.x
|
||||||
|
# right.y = 0
|
||||||
|
# right = right.normalized()
|
||||||
|
|
||||||
|
# var directionAdjusted = (
|
||||||
|
# forward * _inputDir.y + right * _inputDir.x
|
||||||
|
# ).normalized()
|
||||||
|
# if directionAdjusted.length() <= 0.01:
|
||||||
|
# return
|
||||||
|
|
||||||
|
# if rotate:
|
||||||
|
# var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
|
||||||
|
# rotate.rotation.y = targetRot
|
||||||
|
|
||||||
|
# var speed = walkSpeed
|
||||||
|
# if _running:
|
||||||
|
# speed = runSpeed
|
||||||
|
|
||||||
|
# body.velocity.x = directionAdjusted.x * speed
|
||||||
|
# body.velocity.z = directionAdjusted.z * speed
|
||||||
|
|
||||||
|
# func _applyFriction(delta:float) -> void:
|
||||||
|
# body.velocity.x *= delta * FRICTION
|
||||||
|
# body.velocity.z *= delta * FRICTION
|
||||||
|
|
||||||
|
# #
|
||||||
|
# # Protected Methods
|
||||||
|
# #
|
||||||
|
# func canMove() -> bool:
|
||||||
|
# return true
|
||||||
|
|
||||||
|
# #
|
||||||
|
# # Callbacks
|
||||||
|
# #
|
||||||
|
# func _enter_tree() -> void:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
# func _physics_process(delta:float) -> void:
|
||||||
|
# if Engine.is_editor_hint():
|
||||||
|
# return
|
||||||
|
|
||||||
|
# if !body:
|
||||||
|
# return
|
||||||
|
|
||||||
|
# _applyGravity()
|
||||||
|
# _applyFriction(delta)
|
||||||
|
# _applyMovement()
|
||||||
|
# body.move_and_slide()
|
||||||
@@ -32,3 +32,12 @@ class_name NPC extends CharacterBody3D
|
|||||||
if _interact:
|
if _interact:
|
||||||
return _interact.interactType
|
return _interact.interactType
|
||||||
return NPCInteract.InteractType.NONE
|
return NPCInteract.InteractType.NONE
|
||||||
|
|
||||||
|
@export var interactText:String:
|
||||||
|
set(value):
|
||||||
|
if _interact:
|
||||||
|
_interact.interactText = value
|
||||||
|
get:
|
||||||
|
if _interact:
|
||||||
|
return _interact.interactText
|
||||||
|
return ""
|
||||||
@@ -31,6 +31,7 @@ body = NodePath("../..")
|
|||||||
|
|
||||||
[node name="NPCInteract" type="Node" parent="Scripts"]
|
[node name="NPCInteract" type="Node" parent="Scripts"]
|
||||||
script = ExtResource("3_binvk")
|
script = ExtResource("3_binvk")
|
||||||
|
interactText = ""
|
||||||
metadata/_custom_type_script = "uid://dunhfgdwp8wjh"
|
metadata/_custom_type_script = "uid://dunhfgdwp8wjh"
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
39
_archive/entity/npc/NPCInteract.gd
Normal file
39
_archive/entity/npc/NPCInteract.gd
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
@tool
|
||||||
|
class_name NPCInteract extends Node
|
||||||
|
|
||||||
|
enum InteractType {
|
||||||
|
NONE,
|
||||||
|
TEXT,
|
||||||
|
CUTSCENE
|
||||||
|
}
|
||||||
|
|
||||||
|
@export var interactType:InteractType = InteractType.NONE
|
||||||
|
@export var interactText:Array[String] = []
|
||||||
|
|
||||||
|
var interactTextIndex:int = 0
|
||||||
|
|
||||||
|
func onInteract(_player:Player) -> void:
|
||||||
|
if interactType == InteractType.TEXT:
|
||||||
|
interactTextIndex = 0
|
||||||
|
UI.TEXTBOX.setText(interactText[interactTextIndex])
|
||||||
|
UI.TEXTBOX.textboxClosing.connect(onTextboxClosing)
|
||||||
|
return
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
func onInteractable(player:Player) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func onNotInteractable(player:Player) -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _exit_tree() -> void:
|
||||||
|
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
||||||
|
|
||||||
|
func onTextboxClosing() -> void:
|
||||||
|
interactTextIndex += 1
|
||||||
|
if interactTextIndex < interactText.size():
|
||||||
|
UI.TEXTBOX.setText(interactText[interactTextIndex])
|
||||||
|
else:
|
||||||
|
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
||||||
|
UI.TEXTBOX.setText("")
|
||||||
2
_archive/entity/npc/NPCMovement.gd
Normal file
2
_archive/entity/npc/NPCMovement.gd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# @tool
|
||||||
|
# class_name NPCMovement extends "res://entity/EntityMovement.gd"
|
||||||
22
_archive/entity/player/Player.gd
Normal file
22
_archive/entity/player/Player.gd
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# @tool
|
||||||
|
# class_name Player extends CharacterBody3D
|
||||||
|
|
||||||
|
# @export var _movement:PlayerMovement
|
||||||
|
|
||||||
|
# @export var walkSpeed:float:
|
||||||
|
# set(value):
|
||||||
|
# if _movement:
|
||||||
|
# _movement.walkSpeed = value
|
||||||
|
# get:
|
||||||
|
# if _movement:
|
||||||
|
# return _movement.walkSpeed
|
||||||
|
# return 0.0
|
||||||
|
|
||||||
|
# @export var runSpeed:float:
|
||||||
|
# set(value):
|
||||||
|
# if _movement:
|
||||||
|
# _movement.runSpeed = value
|
||||||
|
# get:
|
||||||
|
# if _movement:
|
||||||
|
# return _movement.runSpeed
|
||||||
|
# return 0.0
|
||||||
|
Before Width: | Height: | Size: 237 B After Width: | Height: | Size: 237 B |
@@ -3,7 +3,7 @@
|
|||||||
importer="texture"
|
importer="texture"
|
||||||
type="CompressedTexture2D"
|
type="CompressedTexture2D"
|
||||||
uid="uid://xx3qp5xh7tgu"
|
uid="uid://xx3qp5xh7tgu"
|
||||||
path.s3tc="res://.godot/imported/Player.png-44a553acafadade6fc26fd4f7692a8d9.s3tc.ctex"
|
path.s3tc="res://.godot/imported/Player.png-375a5d516004cad2a06e60ddde70664e.s3tc.ctex"
|
||||||
metadata={
|
metadata={
|
||||||
"imported_formats": ["s3tc_bptc"],
|
"imported_formats": ["s3tc_bptc"],
|
||||||
"vram_texture": true
|
"vram_texture": true
|
||||||
@@ -11,8 +11,8 @@ metadata={
|
|||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://entity/player/Player.png"
|
source_file="res://_archive/entity/player/Player.png"
|
||||||
dest_files=["res://.godot/imported/Player.png-44a553acafadade6fc26fd4f7692a8d9.s3tc.ctex"]
|
dest_files=["res://.godot/imported/Player.png-375a5d516004cad2a06e60ddde70664e.s3tc.ctex"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
@tool
|
|
||||||
class_name EntityMovement extends Node
|
|
||||||
|
|
||||||
const FRICTION = 0.01
|
|
||||||
const WALK_SPEED_DEFAULT = 8
|
|
||||||
const RUN_SPEED_DEFAULT = 12
|
|
||||||
|
|
||||||
var _inputDir:Vector2 = Vector2.ZERO
|
|
||||||
var _running:bool = false
|
|
||||||
|
|
||||||
@export var body:CharacterBody3D
|
|
||||||
@export var rotate:Node3D
|
|
||||||
@export var walkSpeed:float = WALK_SPEED_DEFAULT
|
|
||||||
@export var runSpeed:float = RUN_SPEED_DEFAULT
|
|
||||||
|
|
||||||
#
|
|
||||||
# Private Methods
|
|
||||||
#
|
|
||||||
func _applyGravity() -> void:
|
|
||||||
if !body.is_on_floor():
|
|
||||||
body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
|
||||||
|
|
||||||
func _applyMovement() -> void:
|
|
||||||
if !canMove():
|
|
||||||
return
|
|
||||||
|
|
||||||
var cameraCurrent = get_viewport().get_camera_3d()
|
|
||||||
if !cameraCurrent:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Use camera orientation for movement direction
|
|
||||||
var camBasis = cameraCurrent.global_transform.basis
|
|
||||||
|
|
||||||
# Forward and right vectors, ignore vertical component
|
|
||||||
var forward = -camBasis.z
|
|
||||||
forward.y = 0
|
|
||||||
forward = forward.normalized()
|
|
||||||
var right = camBasis.x
|
|
||||||
right.y = 0
|
|
||||||
right = right.normalized()
|
|
||||||
|
|
||||||
var directionAdjusted = (
|
|
||||||
forward * _inputDir.y + right * _inputDir.x
|
|
||||||
).normalized()
|
|
||||||
if directionAdjusted.length() <= 0.01:
|
|
||||||
return
|
|
||||||
|
|
||||||
if rotate:
|
|
||||||
var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
|
|
||||||
rotate.rotation.y = targetRot
|
|
||||||
|
|
||||||
var speed = walkSpeed
|
|
||||||
if _running:
|
|
||||||
speed = runSpeed
|
|
||||||
|
|
||||||
body.velocity.x = directionAdjusted.x * speed
|
|
||||||
body.velocity.z = directionAdjusted.z * speed
|
|
||||||
|
|
||||||
func _applyFriction(delta:float) -> void:
|
|
||||||
body.velocity.x *= delta * FRICTION
|
|
||||||
body.velocity.z *= delta * FRICTION
|
|
||||||
|
|
||||||
#
|
|
||||||
# Protected Methods
|
|
||||||
#
|
|
||||||
func canMove() -> bool:
|
|
||||||
return true
|
|
||||||
|
|
||||||
#
|
|
||||||
# Callbacks
|
|
||||||
#
|
|
||||||
func _enter_tree() -> void:
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _physics_process(delta:float) -> void:
|
|
||||||
if Engine.is_editor_hint():
|
|
||||||
return
|
|
||||||
|
|
||||||
if !body:
|
|
||||||
return
|
|
||||||
|
|
||||||
_applyGravity()
|
|
||||||
_applyFriction(delta)
|
|
||||||
_applyMovement()
|
|
||||||
body.move_and_slide()
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
@tool
|
|
||||||
class_name NPCInteract extends Node
|
|
||||||
|
|
||||||
enum InteractType {
|
|
||||||
NONE,
|
|
||||||
TEXT,
|
|
||||||
CUTSCENE
|
|
||||||
}
|
|
||||||
|
|
||||||
@export var interactType:InteractType = InteractType.NONE
|
|
||||||
|
|
||||||
func onInteract(player:Player) -> void:
|
|
||||||
print("NPC Interacted with by Player: %s" % player.name)
|
|
||||||
pass
|
|
||||||
|
|
||||||
func onInteractable(player:Player) -> void:
|
|
||||||
pass
|
|
||||||
|
|
||||||
func onNotInteractable(player:Player) -> void:
|
|
||||||
pass
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
@tool
|
|
||||||
class_name NPCMovement extends "res://entity/EntityMovement.gd"
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
@tool
|
|
||||||
class_name Player extends CharacterBody3D
|
|
||||||
|
|
||||||
@export var _movement:PlayerMovement
|
|
||||||
|
|
||||||
@export var walkSpeed:float:
|
|
||||||
set(value):
|
|
||||||
if _movement:
|
|
||||||
_movement.walkSpeed = value
|
|
||||||
get:
|
|
||||||
if _movement:
|
|
||||||
return _movement.walkSpeed
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
@export var runSpeed:float:
|
|
||||||
set(value):
|
|
||||||
if _movement:
|
|
||||||
_movement.runSpeed = value
|
|
||||||
get:
|
|
||||||
if _movement:
|
|
||||||
return _movement.runSpeed
|
|
||||||
return 0.0
|
|
||||||
78
item/Inventory.gd
Normal file
78
item/Inventory.gd
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
class_name Inventory
|
||||||
|
const Item = preload("res://item/Item.gd")
|
||||||
|
const ItemStack = preload("res://item/ItemStack.gd")
|
||||||
|
|
||||||
|
var items:Array[ItemStack] = []
|
||||||
|
|
||||||
|
enum InventorySortType {
|
||||||
|
ITEM_TYPE,
|
||||||
|
ITEM_KEY
|
||||||
|
}
|
||||||
|
|
||||||
|
signal itemAdded(item:Item)
|
||||||
|
signal itemRemoved(item:Item)
|
||||||
|
signal itemQuantityChanged(item:Item, quantity:int)
|
||||||
|
signal inventorySorted(sortBy:InventorySortType, reverse:bool)
|
||||||
|
|
||||||
|
func setItem(item:Item, quantity:int) -> void:
|
||||||
|
if quantity < 0:
|
||||||
|
push_error("Cannot set item quantity to negative value, using 0")
|
||||||
|
quantity = 0
|
||||||
|
|
||||||
|
# Is item already in inventory?
|
||||||
|
for itemStack in items:
|
||||||
|
if itemStack.item != item:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Item stack already present.
|
||||||
|
if quantity == 0:
|
||||||
|
items.erase(itemStack)
|
||||||
|
itemRemoved.emit(item)
|
||||||
|
itemQuantityChanged.emit(item, 0)
|
||||||
|
else:
|
||||||
|
itemStack.quantity = quantity
|
||||||
|
itemQuantityChanged.emit(item, quantity)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Not in stack, create new stack
|
||||||
|
var stack:ItemStack = ItemStack.new()
|
||||||
|
stack.item = item
|
||||||
|
stack.quantity = quantity
|
||||||
|
items.append(stack)
|
||||||
|
itemAdded.emit(item)
|
||||||
|
itemQuantityChanged.emit(item, quantity)
|
||||||
|
|
||||||
|
func getItemQuantity(item:Item) -> int:
|
||||||
|
for itemStack in items:
|
||||||
|
if itemStack.item == item:
|
||||||
|
return itemStack.quantity
|
||||||
|
return 0
|
||||||
|
|
||||||
|
func addItem(item:Item, quantity:int = 1) -> void:
|
||||||
|
# Add can only take positive quantities, otherwise use set or remove
|
||||||
|
if quantity <= 0:
|
||||||
|
push_error("Cannot add non-positive item quantity")
|
||||||
|
return
|
||||||
|
self.setItem(item, self.getItemQuantity(item) + quantity)
|
||||||
|
|
||||||
|
func removeItem(item:Item) -> void:
|
||||||
|
self.setItem(item, 0)
|
||||||
|
|
||||||
|
func sort(sortBy:InventorySortType, reverse:bool = false) -> void:
|
||||||
|
match sortBy:
|
||||||
|
InventorySortType.ITEM_TYPE:
|
||||||
|
items.sort_custom(_sortByItemType)
|
||||||
|
InventorySortType.ITEM_KEY:
|
||||||
|
items.sort_custom(_sortByItemKey)
|
||||||
|
|
||||||
|
if reverse:
|
||||||
|
items.reverse()
|
||||||
|
|
||||||
|
inventorySorted.emit(sortBy, reverse)
|
||||||
|
|
||||||
|
# Sorters
|
||||||
|
func _sortByItemType(a:ItemStack, b:ItemStack) -> int:
|
||||||
|
return int(a.item.itemType) - int(b.item.itemType)
|
||||||
|
|
||||||
|
func _sortByItemKey(a:ItemStack, b:ItemStack) -> int:
|
||||||
|
return a.item.key.casecmp_to(b.item.key)
|
||||||
1
item/Inventory.gd.uid
Normal file
1
item/Inventory.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://6ekrdnirg8vr
|
||||||
26
item/Item.gd
Normal file
26
item/Item.gd
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
class_name Item
|
||||||
|
|
||||||
|
# Enum Types
|
||||||
|
enum ItemType {
|
||||||
|
NULL,
|
||||||
|
|
||||||
|
MEDICINE,
|
||||||
|
KEY_ITEM,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Properties
|
||||||
|
var itemType:ItemType
|
||||||
|
var key:String
|
||||||
|
|
||||||
|
# Item Constructor
|
||||||
|
func _init(key:String, itemType:ItemType) -> void:
|
||||||
|
self.key = key
|
||||||
|
self.itemType = itemType
|
||||||
|
|
||||||
|
func getName() -> String:
|
||||||
|
# For now just return key
|
||||||
|
return self.key
|
||||||
|
|
||||||
|
# Item Table
|
||||||
|
static var NULL:Item = Item.new("NULL", ItemType.NULL)
|
||||||
|
static var POTION:Item = Item.new("POTION", ItemType.MEDICINE)
|
||||||
1
item/Item.gd.uid
Normal file
1
item/Item.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dtav0cqc1bn6g
|
||||||
6
item/ItemStack.gd
Normal file
6
item/ItemStack.gd
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class_name ItemStack
|
||||||
|
|
||||||
|
const Item = preload("res://item/Item.gd")
|
||||||
|
|
||||||
|
var item:Item = Item.NULL
|
||||||
|
var quantity:int = 0
|
||||||
1
item/ItemStack.gd.uid
Normal file
1
item/ItemStack.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://c3ytuwkcshyrl
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://d0ywgijpuqy0r"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://xe6pcuq741xi" path="res://map/TestMap.gd" id="1_6ms5s"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cluuhtfjeodwb" path="res://map/TestMapBase.tscn" id="1_ox0si"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://entity/player/Player.tscn" id="2_0d2qr"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://kabs7mopalmo" path="res://entity/npc/NPC.tscn" id="3_0vfw4"]
|
|
||||||
|
|
||||||
[node name="TestMap" type="Node3D"]
|
|
||||||
script = ExtResource("1_6ms5s")
|
|
||||||
|
|
||||||
[node name="TestMapBase" parent="." instance=ExtResource("1_ox0si")]
|
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource("2_0d2qr")]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 11.5777, 1.09878, 0)
|
|
||||||
walkSpeed = 8.0
|
|
||||||
runSpeed = 12.0
|
|
||||||
|
|
||||||
[node name="NPC" parent="." instance=ExtResource("3_0vfw4")]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.3026, 1.11551, -2.12904)
|
|
||||||
interactType = 1
|
|
||||||
|
|
||||||
[node name="Meta" type="Node" parent="."]
|
|
||||||
|
|
||||||
[node name="Cutscenes" type="Node" parent="Meta"]
|
|
||||||
@@ -23,12 +23,12 @@ func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
|
|||||||
map.add_child(newMapInstance)
|
map.add_child(newMapInstance)
|
||||||
|
|
||||||
# Find Player.
|
# Find Player.
|
||||||
if playerDestinationNodeName:
|
# if playerDestinationNodeName:
|
||||||
var player = newMapInstance.get_node("Player")
|
# var player = newMapInstance.get_node("Player")
|
||||||
var destNode = newMapInstance.get_node(playerDestinationNodeName)
|
# var destNode = newMapInstance.get_node(playerDestinationNodeName)
|
||||||
if player && player is Player && destNode:
|
# if player && player is Player && destNode:
|
||||||
player.global_position = destNode.global_position
|
# player.global_position = destNode.global_position
|
||||||
player.global_rotation.y = destNode.global_rotation.y
|
# player.global_rotation.y = destNode.global_rotation.y
|
||||||
elif playerDestinationNodeName:
|
# elif playerDestinationNodeName:
|
||||||
push_error("Player, or destination node not found in new map.")
|
# push_error("Player, or destination node not found in new map.")
|
||||||
pass
|
# pass
|
||||||
|
|||||||
18
overworld/entity/Entity.gd
Normal file
18
overworld/entity/Entity.gd
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class_name Entity extends CharacterBody3D
|
||||||
|
|
||||||
|
enum MovementType {
|
||||||
|
NONE,
|
||||||
|
DISABLED,
|
||||||
|
PLAYER
|
||||||
|
}
|
||||||
|
|
||||||
|
enum InteractType {
|
||||||
|
NONE,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
# Movement settings
|
||||||
|
@export var movementType:MovementType = MovementType.NONE
|
||||||
|
|
||||||
|
# Interaction settings
|
||||||
|
@export var interactType:InteractType = InteractType.NONE
|
||||||
1
overworld/entity/Entity.gd.uid
Normal file
1
overworld/entity/Entity.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://c8146flooxeue
|
||||||
70
overworld/entity/Entity.tscn
Normal file
70
overworld/entity/Entity.tscn
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
[gd_scene load_steps=12 format=3 uid="uid://by4a0r2hp0w6s"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://c8146flooxeue" path="res://overworld/entity/Entity.gd" id="1_8e8ef"]
|
||||||
|
[ext_resource type="Script" uid="uid://cj122th32iabx" path="res://overworld/entity/EntityMovement.gd" id="2_sfgsm"]
|
||||||
|
[ext_resource type="Script" uid="uid://8is1soq6i282" path="res://overworld/entity/EntityInteractingArea.gd" id="3_bhm0o"]
|
||||||
|
[ext_resource type="Script" uid="uid://cr03t63s321wp" path="res://overworld/entity/EntityInteractableArea.gd" id="4_e1jqj"]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_8e8ef"]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleMesh" id="CapsuleMesh_sfgsm"]
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8e8ef"]
|
||||||
|
shading_mode = 0
|
||||||
|
albedo_color = Color(0.521569, 1, 1, 1)
|
||||||
|
|
||||||
|
[sub_resource type="BoxMesh" id="BoxMesh_8e8ef"]
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_sfgsm"]
|
||||||
|
shading_mode = 0
|
||||||
|
albedo_color = Color(1, 0.518134, 0.620745, 1)
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_sfgsm"]
|
||||||
|
size = Vector3(0.689728, 0.52002, 0.796997)
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_bhm0o"]
|
||||||
|
size = Vector3(1.3, 1.3, 1.3)
|
||||||
|
|
||||||
|
[node name="Entity" type="CharacterBody3D"]
|
||||||
|
script = ExtResource("1_8e8ef")
|
||||||
|
metadata/_custom_type_script = "uid://c8146flooxeue"
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
shape = SubResource("CapsuleShape3D_8e8ef")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
mesh = SubResource("CapsuleMesh_sfgsm")
|
||||||
|
surface_material_override/0 = SubResource("StandardMaterial3D_8e8ef")
|
||||||
|
|
||||||
|
[node name="Nose" type="Node3D" parent="."]
|
||||||
|
transform = Transform3D(0.393905, 0, 0, 0, 0.393905, 0, 0, 0, 0.393905, 0.571181, 0.340915, 0)
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="Nose"]
|
||||||
|
mesh = SubResource("BoxMesh_8e8ef")
|
||||||
|
surface_material_override/0 = SubResource("StandardMaterial3D_sfgsm")
|
||||||
|
|
||||||
|
[node name="Components" type="Node" parent="."]
|
||||||
|
|
||||||
|
[node name="Movement" type="Node" parent="Components" node_paths=PackedStringArray("entity", "interactingArea")]
|
||||||
|
script = ExtResource("2_sfgsm")
|
||||||
|
entity = NodePath("../..")
|
||||||
|
interactingArea = NodePath("../../EntityInteractingArea")
|
||||||
|
|
||||||
|
[node name="EntityInteractingArea" type="Area3D" parent="." node_paths=PackedStringArray("entity")]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 2
|
||||||
|
script = ExtResource("3_bhm0o")
|
||||||
|
entity = NodePath("..")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="EntityInteractingArea"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.604726, 0, 0)
|
||||||
|
shape = SubResource("BoxShape3D_sfgsm")
|
||||||
|
|
||||||
|
[node name="EntityInteractableArea" type="Area3D" parent="." node_paths=PackedStringArray("entity")]
|
||||||
|
collision_layer = 2
|
||||||
|
collision_mask = 0
|
||||||
|
script = ExtResource("4_e1jqj")
|
||||||
|
entity = NodePath("..")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="EntityInteractableArea"]
|
||||||
|
shape = SubResource("BoxShape3D_bhm0o")
|
||||||
16
overworld/entity/EntityInteractableArea.gd
Normal file
16
overworld/entity/EntityInteractableArea.gd
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class_name EntityInteractableArea extends Area3D
|
||||||
|
const Entity = preload("res://overworld/entity/Entity.gd")
|
||||||
|
|
||||||
|
@export var entity:Entity
|
||||||
|
|
||||||
|
func isInteractable() -> bool:
|
||||||
|
return entity && entity.interactType != Entity.InteractType.NONE
|
||||||
|
|
||||||
|
func onInteract() -> void:
|
||||||
|
if !isInteractable():
|
||||||
|
return
|
||||||
|
|
||||||
|
if entity.interactType == Entity.InteractType.NONE:
|
||||||
|
return
|
||||||
|
|
||||||
|
print("Entity Interacted")
|
||||||
1
overworld/entity/EntityInteractableArea.gd.uid
Normal file
1
overworld/entity/EntityInteractableArea.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cr03t63s321wp
|
||||||
33
overworld/entity/EntityInteractingArea.gd
Normal file
33
overworld/entity/EntityInteractingArea.gd
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
class_name EntityInteractingArea extends Area3D
|
||||||
|
const Entity = preload("res://overworld/entity/Entity.gd")
|
||||||
|
|
||||||
|
var interactableAreas:Array[EntityInteractableArea] = []
|
||||||
|
@export var entity:Entity
|
||||||
|
|
||||||
|
func hasInteraction() -> bool:
|
||||||
|
return true
|
||||||
|
|
||||||
|
func interact() -> void:
|
||||||
|
for area in interactableAreas:
|
||||||
|
area.onInteract()
|
||||||
|
|
||||||
|
func _enter_tree() -> void:
|
||||||
|
self.area_entered.connect(_onAreaEntered)
|
||||||
|
self.area_exited.connect(_onAreaExited)
|
||||||
|
|
||||||
|
func _exit_tree() -> void:
|
||||||
|
self.area_entered.disconnect(_onAreaEntered)
|
||||||
|
self.area_exited.disconnect(_onAreaExited)
|
||||||
|
|
||||||
|
func _onAreaEntered(area:Area3D) -> void:
|
||||||
|
if area is EntityInteractableArea:
|
||||||
|
if area.entity == entity:
|
||||||
|
return
|
||||||
|
if !area.isInteractable():
|
||||||
|
return
|
||||||
|
print("EntityInteractingArea: Area Entered")
|
||||||
|
interactableAreas.append(area)
|
||||||
|
|
||||||
|
func _onAreaExited(area:Area3D) -> void:
|
||||||
|
print("EntityInteractingArea: Area Exited")
|
||||||
|
interactableAreas.erase(area)
|
||||||
1
overworld/entity/EntityInteractingArea.gd.uid
Normal file
1
overworld/entity/EntityInteractingArea.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://8is1soq6i282
|
||||||
80
overworld/entity/EntityMovement.gd
Normal file
80
overworld/entity/EntityMovement.gd
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
class_name EntityMovement extends Node
|
||||||
|
|
||||||
|
const FRICTION = 0.01
|
||||||
|
const WALK_SPEED_DEFAULT = 8
|
||||||
|
const RUN_SPEED_DEFAULT = 12
|
||||||
|
|
||||||
|
# var _inputDir:Vector2 = Vector2.ZERO
|
||||||
|
# var _running:bool = false
|
||||||
|
|
||||||
|
@export var entity:Entity
|
||||||
|
@export var interactingArea:EntityInteractingArea
|
||||||
|
# @export var rotate:Node3D
|
||||||
|
@export var walkSpeed:float = WALK_SPEED_DEFAULT
|
||||||
|
# @export var runSpeed:float = RUN_SPEED_DEFAULT
|
||||||
|
|
||||||
|
#
|
||||||
|
# Private Methods
|
||||||
|
#
|
||||||
|
func _applyGravity() -> void:
|
||||||
|
if !entity.is_on_floor():
|
||||||
|
entity.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||||
|
|
||||||
|
func _applyPlayerMovement(_delta:float):
|
||||||
|
if Input.is_action_just_pressed("interact") && interactingArea && interactingArea.hasInteraction():
|
||||||
|
interactingArea.interact()
|
||||||
|
return
|
||||||
|
|
||||||
|
var inputDir:Vector2 = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()
|
||||||
|
var cameraCurrent = get_viewport().get_camera_3d()
|
||||||
|
if !cameraCurrent:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Use camera orientation for movement direction
|
||||||
|
var camBasis = cameraCurrent.global_transform.basis
|
||||||
|
|
||||||
|
# Forward and right vectors, ignore vertical component
|
||||||
|
var forward = -camBasis.z
|
||||||
|
forward.y = 0
|
||||||
|
forward = forward.normalized()
|
||||||
|
var right = camBasis.x
|
||||||
|
right.y = 0
|
||||||
|
right = right.normalized()
|
||||||
|
|
||||||
|
var directionAdjusted = (forward * inputDir.y + right * inputDir.x).normalized()
|
||||||
|
if directionAdjusted.length() <= 0.01:
|
||||||
|
return
|
||||||
|
|
||||||
|
var speed = walkSpeed
|
||||||
|
entity.velocity.x = directionAdjusted.x * speed
|
||||||
|
entity.velocity.z = directionAdjusted.z * speed
|
||||||
|
|
||||||
|
func _applyMovement(delta:float) -> void:
|
||||||
|
if !_canMove():
|
||||||
|
return
|
||||||
|
|
||||||
|
if entity.movementType == Entity.MovementType.PLAYER:
|
||||||
|
_applyPlayerMovement(delta)
|
||||||
|
|
||||||
|
func _applyFriction(delta:float) -> void:
|
||||||
|
entity.velocity.x *= delta * FRICTION
|
||||||
|
entity.velocity.z *= delta * FRICTION
|
||||||
|
|
||||||
|
func _canMove() -> bool:
|
||||||
|
return true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Callbacks
|
||||||
|
#
|
||||||
|
func _enter_tree() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _physics_process(delta:float) -> void:
|
||||||
|
# Entity required to move
|
||||||
|
if !entity || entity.movementType == Entity.MovementType.DISABLED || !entity.visible:
|
||||||
|
return
|
||||||
|
|
||||||
|
_applyGravity()
|
||||||
|
_applyFriction(delta)
|
||||||
|
_applyMovement(delta)
|
||||||
|
entity.move_and_slide()
|
||||||
1
overworld/entity/EntityMovement.gd.uid
Normal file
1
overworld/entity/EntityMovement.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cj122th32iabx
|
||||||
20
overworld/map/TestMap.tscn
Normal file
20
overworld/map/TestMap.tscn
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
[gd_scene load_steps=4 format=3 uid="uid://d0ywgijpuqy0r"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://xe6pcuq741xi" path="res://overworld/map/TestMap.gd" id="1_6ms5s"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cluuhtfjeodwb" path="res://overworld/map/TestMapBase.tscn" id="1_ox0si"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://by4a0r2hp0w6s" path="res://overworld/entity/Entity.tscn" id="2_jmygs"]
|
||||||
|
|
||||||
|
[node name="TestMap" type="Node3D"]
|
||||||
|
script = ExtResource("1_6ms5s")
|
||||||
|
|
||||||
|
[node name="NotPlayer" parent="." instance=ExtResource("2_jmygs")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00883961, 1.11219, 0.0142021)
|
||||||
|
|
||||||
|
[node name="TestMapBase" parent="." instance=ExtResource("1_ox0si")]
|
||||||
|
|
||||||
|
[node name="Player" parent="." instance=ExtResource("2_jmygs")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.1915, 1.05, 0.125589)
|
||||||
|
movementType = 2
|
||||||
|
|
||||||
|
[node name="Camera3D" type="Camera3D" parent="."]
|
||||||
|
transform = Transform3D(-0.0384888, -0.605488, 0.794923, -0.0292824, 0.795854, 0.60478, -0.99883, 0, -0.0483617, 5.96324, 4.42257, 0)
|
||||||
Reference in New Issue
Block a user