Godot 4.5.1
This commit is contained in:
@@ -17,69 +17,69 @@ var _running:bool = false
|
||||
# Private Methods
|
||||
#
|
||||
func _applyGravity() -> void:
|
||||
if !body.is_on_floor():
|
||||
body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||
if !body.is_on_floor():
|
||||
body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||
|
||||
func _applyMovement() -> void:
|
||||
if !canMove():
|
||||
return
|
||||
if !canMove():
|
||||
return
|
||||
|
||||
var cameraCurrent = get_viewport().get_camera_3d()
|
||||
if !cameraCurrent:
|
||||
return
|
||||
var cameraCurrent = get_viewport().get_camera_3d()
|
||||
if !cameraCurrent:
|
||||
return
|
||||
|
||||
# Use camera orientation for movement direction
|
||||
var camBasis = cameraCurrent.global_transform.basis
|
||||
# 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()
|
||||
# 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 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
|
||||
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
|
||||
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
|
||||
body.velocity.x *= delta * FRICTION
|
||||
body.velocity.z *= delta * FRICTION
|
||||
|
||||
#
|
||||
# Protected Methods
|
||||
# Protected Methods
|
||||
#
|
||||
func canMove() -> bool:
|
||||
return true
|
||||
return true
|
||||
|
||||
#
|
||||
# Callbacks
|
||||
#
|
||||
func _enter_tree() -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
func _physics_process(delta:float) -> void:
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
|
||||
if !body:
|
||||
return
|
||||
if !body:
|
||||
return
|
||||
|
||||
_applyGravity()
|
||||
_applyFriction(delta)
|
||||
_applyMovement()
|
||||
body.move_and_slide()
|
||||
_applyGravity()
|
||||
_applyFriction(delta)
|
||||
_applyMovement()
|
||||
body.move_and_slide()
|
||||
|
||||
@@ -6,29 +6,29 @@ class_name NPC extends CharacterBody3D
|
||||
|
||||
# NPC Movement Accessors
|
||||
@export var walkSpeed:float:
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.walkSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.walkSpeed
|
||||
return 0
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.walkSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.walkSpeed
|
||||
return 0
|
||||
|
||||
@export var runSpeed:float:
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.runSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.runSpeed
|
||||
return 0
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.runSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.runSpeed
|
||||
return 0
|
||||
|
||||
# NPC Interact Accessors
|
||||
@export var interactType:NPCInteract.InteractType:
|
||||
set(value):
|
||||
if _interact:
|
||||
_interact.interactType = value
|
||||
get:
|
||||
if _interact:
|
||||
return _interact.interactType
|
||||
return NPCInteract.InteractType.NONE
|
||||
set(value):
|
||||
if _interact:
|
||||
_interact.interactType = value
|
||||
get:
|
||||
if _interact:
|
||||
return _interact.interactType
|
||||
return NPCInteract.InteractType.NONE
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
class_name NPCInteract extends Node
|
||||
|
||||
enum InteractType {
|
||||
NONE,
|
||||
TEXT,
|
||||
CUTSCENE
|
||||
NONE,
|
||||
TEXT,
|
||||
CUTSCENE
|
||||
}
|
||||
|
||||
@export var interactType:InteractType = InteractType.NONE
|
||||
|
||||
func onInteract(player:Player) -> void:
|
||||
print("NPC Interacted with by Player: %s" % player.name)
|
||||
pass
|
||||
print("NPC Interacted with by Player: %s" % player.name)
|
||||
pass
|
||||
|
||||
func onInteractable(player:Player) -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
func onNotInteractable(player:Player) -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class_name NPCTest extends Node
|
||||
|
||||
func onInteract(playerEntity: Player) -> void:
|
||||
print("Player has interacted with the NPC.")
|
||||
UI.TEXTBOX.setText("You have interacted with the NPC.")
|
||||
print("Player has interacted with the NPC.")
|
||||
UI.TEXTBOX.setText("You have interacted with the NPC.")
|
||||
|
||||
@@ -4,19 +4,19 @@ 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
|
||||
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
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.runSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.runSpeed
|
||||
return 0.0
|
||||
|
||||
@@ -19,6 +19,8 @@ dest_files=["res://.godot/imported/Player.png-44a553acafadade6fc26fd4f7692a8d9.s
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
@@ -26,6 +28,10 @@ mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
|
||||
@@ -10,18 +10,18 @@ const CAMERA_PIXEL_SCALE = 1.0
|
||||
var angle = 0.0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if !camera || !target:
|
||||
return
|
||||
|
||||
# Follow target
|
||||
# camera.global_transform.origin = target.global_transform.origin
|
||||
if !camera || !target:
|
||||
return
|
||||
|
||||
# Follow target
|
||||
# camera.global_transform.origin = target.global_transform.origin
|
||||
|
||||
# # Spin around origin.
|
||||
# var rotation_speed = 1 # Radians per second
|
||||
# angle += rotation_speed * delta
|
||||
# var radius = 3.0
|
||||
# var offset = Vector3(radius * sin(angle), 2.0, radius * cos(angle))
|
||||
# camera.global_transform.origin += offset
|
||||
# # Spin around origin.
|
||||
# var rotation_speed = 1 # Radians per second
|
||||
# angle += rotation_speed * delta
|
||||
# var radius = 3.0
|
||||
# var offset = Vector3(radius * sin(angle), 2.0, radius * cos(angle))
|
||||
# camera.global_transform.origin += offset
|
||||
|
||||
# # Look at target
|
||||
# camera.look_at(target.global_transform.origin, Vector3.UP)
|
||||
# # Look at target
|
||||
# camera.look_at(target.global_transform.origin, Vector3.UP)
|
||||
|
||||
@@ -4,10 +4,10 @@ class_name PlayerInput extends Node
|
||||
@export var movement:PlayerMovement
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("pause"):
|
||||
PAUSE.menuPause()
|
||||
if Input.is_action_just_pressed("pause"):
|
||||
PAUSE.menuPause()
|
||||
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
interaction.interact()
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
interaction.interact()
|
||||
|
||||
movement._inputDir = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()
|
||||
movement._inputDir = Input.get_vector("move_left", "move_right", "move_back", "move_forward").normalized()
|
||||
|
||||
@@ -4,24 +4,24 @@ class_name PlayerInteraction extends Node
|
||||
@export var player:CharacterBody3D
|
||||
|
||||
func canInteract() -> bool:
|
||||
if PAUSE.isMovementPaused():
|
||||
return false
|
||||
return true
|
||||
if PAUSE.isMovementPaused():
|
||||
return false
|
||||
return true
|
||||
|
||||
func interact() -> void:
|
||||
if !canInteract():
|
||||
return
|
||||
if !canInteract():
|
||||
return
|
||||
|
||||
var overlapping = interactableArea.get_overlapping_areas()
|
||||
var interactable: InteractableArea = null
|
||||
var overlapping = interactableArea.get_overlapping_areas()
|
||||
var interactable: InteractableArea = null
|
||||
|
||||
for node in overlapping:
|
||||
if !(node is InteractableArea):
|
||||
continue
|
||||
interactable = node
|
||||
break
|
||||
for node in overlapping:
|
||||
if !(node is InteractableArea):
|
||||
continue
|
||||
interactable = node
|
||||
break
|
||||
|
||||
if !interactable:
|
||||
return
|
||||
if !interactable:
|
||||
return
|
||||
|
||||
interactable.interactEvent.emit(player)
|
||||
interactable.interactEvent.emit(player)
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
class_name PlayerMovement extends "res://entity/EntityMovement.gd"
|
||||
|
||||
func canMove() -> bool:
|
||||
if PAUSE.isMovementPaused():
|
||||
return false
|
||||
return true
|
||||
if PAUSE.isMovementPaused():
|
||||
return false
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user