idk getting back to it
This commit is contained in:
1
entities/npc/NPC.gd
Normal file
1
entities/npc/NPC.gd
Normal file
@@ -0,0 +1 @@
|
|||||||
|
class_name NPC extends CharacterBody3D
|
1
entities/npc/NPC.gd.uid
Normal file
1
entities/npc/NPC.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://crw7ls7t8cwct
|
91
entities/npc/NPC.tscn
Normal file
91
entities/npc/NPC.tscn
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
[gd_scene load_steps=12 format=3 uid="uid://kabs7mopalmo"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://crw7ls7t8cwct" path="res://entities/npc/NPC.gd" id="1_00k55"]
|
||||||
|
[ext_resource type="Script" uid="uid://cmwovncvo1n5o" path="res://entities/npc/NPCTest.gd" id="2_1seh5"]
|
||||||
|
[ext_resource type="Script" uid="uid://b00rxpveu3v4m" path="res://InteractableArea.gd" id="2_x8luf"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entities/player/Player.png" id="4_x8luf"]
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_1seh5"]
|
||||||
|
size = Vector3(16, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_rl6fg"]
|
||||||
|
atlas = ExtResource("4_x8luf")
|
||||||
|
region = Rect2(16, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_q57vx"]
|
||||||
|
atlas = ExtResource("4_x8luf")
|
||||||
|
region = Rect2(48, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_ak4un"]
|
||||||
|
atlas = ExtResource("4_x8luf")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_1ms0h"]
|
||||||
|
atlas = ExtResource("4_x8luf")
|
||||||
|
region = Rect2(32, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_1seh5"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_rl6fg")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_east",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_q57vx")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_north",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_ak4un")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_south",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_1ms0h")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_west",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_x8luf"]
|
||||||
|
radius = 8.5
|
||||||
|
|
||||||
|
[node name="NPC" type="CharacterBody3D"]
|
||||||
|
script = ExtResource("1_00k55")
|
||||||
|
|
||||||
|
[node name="Scripts" type="Node" parent="."]
|
||||||
|
|
||||||
|
[node name="NPCTest" type="Node" parent="Scripts"]
|
||||||
|
script = ExtResource("2_1seh5")
|
||||||
|
|
||||||
|
[node name="InteractableArea" type="Area3D" parent="."]
|
||||||
|
script = ExtResource("2_x8luf")
|
||||||
|
metadata/_custom_type_script = "uid://b00rxpveu3v4m"
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractableArea"]
|
||||||
|
shape = SubResource("BoxShape3D_1seh5")
|
||||||
|
|
||||||
|
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
|
||||||
|
pixel_size = 1.0
|
||||||
|
billboard = 1
|
||||||
|
double_sided = false
|
||||||
|
texture_filter = 0
|
||||||
|
sprite_frames = SubResource("SpriteFrames_1seh5")
|
||||||
|
animation = &"walk_west"
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
shape = SubResource("SphereShape3D_x8luf")
|
||||||
|
|
||||||
|
[connection signal="interactEvent" from="InteractableArea" to="Scripts/NPCTest" method="onInteract"]
|
5
entities/npc/NPCTest.gd
Normal file
5
entities/npc/NPCTest.gd
Normal file
@@ -0,0 +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.")
|
1
entities/npc/NPCTest.gd.uid
Normal file
1
entities/npc/NPCTest.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cmwovncvo1n5o
|
BIN
entities/player/Player.png
Normal file
BIN
entities/player/Player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 237 B |
35
entities/player/Player.png.import
Normal file
35
entities/player/Player.png.import
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://xx3qp5xh7tgu"
|
||||||
|
path.s3tc="res://.godot/imported/Player.png-e32651025a39607688584ad92d58078b.s3tc.ctex"
|
||||||
|
metadata={
|
||||||
|
"imported_formats": ["s3tc_bptc"],
|
||||||
|
"vram_texture": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://entities/player/Player.png"
|
||||||
|
dest_files=["res://.godot/imported/Player.png-e32651025a39607688584ad92d58078b.s3tc.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=2
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=true
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=0
|
BIN
entities/player/Player.png.pxo
Normal file
BIN
entities/player/Player.png.pxo
Normal file
Binary file not shown.
@@ -1,31 +1,83 @@
|
|||||||
[gd_scene load_steps=10 format=3 uid="uid://2ch34sio36nv"]
|
[gd_scene load_steps=14 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://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://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://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://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"]
|
[ext_resource type="Script" uid="uid://bdjgvyiacbg28" path="res://entities/player/PlayerCamera.gd" id="5_g3lhm"]
|
||||||
[ext_resource type="Material" uid="uid://bx0778wr1ge00" path="res://materials/EntityMaterial.tres" id="6_4pwj0"]
|
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entities/player/Player.png" id="7_fmb3c"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2m2ha"]
|
[sub_resource type="SphereShape3D" id="SphereShape3D_4pwj0"]
|
||||||
|
radius = 8.5
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_fmb3c"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_rl6fg"]
|
||||||
|
atlas = ExtResource("7_fmb3c")
|
||||||
|
region = Rect2(16, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_q57vx"]
|
||||||
|
atlas = ExtResource("7_fmb3c")
|
||||||
|
region = Rect2(48, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_ak4un"]
|
||||||
|
atlas = ExtResource("7_fmb3c")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_1ms0h"]
|
||||||
|
atlas = ExtResource("7_fmb3c")
|
||||||
|
region = Rect2(32, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_2rv2u"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_rl6fg")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_east",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_q57vx")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_north",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_ak4un")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_south",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_1ms0h")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"walk_west",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
|
||||||
size = Vector3(0.705444, 0.680542, 1.17688)
|
size = Vector3(10, 16, 8)
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody3D"]
|
[node name="Player" type="CharacterBody3D"]
|
||||||
script = ExtResource("1_24gqh")
|
script = ExtResource("1_24gqh")
|
||||||
|
|
||||||
[node name="Scripts" type="Node" parent="."]
|
[node name="Scripts" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="PlayerMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("player")]
|
[node name="PlayerMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("player", "rotated", "sprite")]
|
||||||
script = ExtResource("2_o7et6")
|
script = ExtResource("2_o7et6")
|
||||||
player = NodePath("../..")
|
player = NodePath("../..")
|
||||||
|
rotated = NodePath("../../PlayerRotated")
|
||||||
|
sprite = NodePath("../../AnimatedSprite3D")
|
||||||
|
|
||||||
[node name="PlayerInteraction" type="Node" parent="Scripts" node_paths=PackedStringArray("interactableArea", "player")]
|
[node name="PlayerInteraction" type="Node" parent="Scripts" node_paths=PackedStringArray("interactableArea", "player")]
|
||||||
script = ExtResource("3_24gqh")
|
script = ExtResource("3_24gqh")
|
||||||
interactableArea = NodePath("../../PlayerInteractableArea")
|
interactableArea = NodePath("../../PlayerRotated/PlayerInteractableArea")
|
||||||
player = NodePath("../..")
|
player = NodePath("../..")
|
||||||
|
|
||||||
[node name="PlayerInput" type="Node" parent="Scripts" node_paths=PackedStringArray("interaction", "movement")]
|
[node name="PlayerInput" type="Node" parent="Scripts" node_paths=PackedStringArray("interaction", "movement")]
|
||||||
@@ -39,18 +91,22 @@ camera = NodePath("../../PlayerCamera")
|
|||||||
target = NodePath("../..")
|
target = NodePath("../..")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
shape = SubResource("CapsuleShape3D_2m2ha")
|
shape = SubResource("SphereShape3D_4pwj0")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
|
|
||||||
mesh = SubResource("QuadMesh_fmb3c")
|
|
||||||
surface_material_override/0 = ExtResource("6_4pwj0")
|
|
||||||
|
|
||||||
[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")
|
|
||||||
|
|
||||||
[node name="PlayerCamera" type="Camera3D" parent="."]
|
[node name="PlayerCamera" type="Camera3D" parent="."]
|
||||||
|
|
||||||
|
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
|
||||||
|
pixel_size = 1.0
|
||||||
|
billboard = 1
|
||||||
|
double_sided = false
|
||||||
|
texture_filter = 0
|
||||||
|
sprite_frames = SubResource("SpriteFrames_2rv2u")
|
||||||
|
animation = &"walk_south"
|
||||||
|
|
||||||
|
[node name="PlayerRotated" type="Node3D" parent="."]
|
||||||
|
|
||||||
|
[node name="PlayerInteractableArea" type="Area3D" parent="PlayerRotated"]
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerRotated/PlayerInteractableArea"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
|
||||||
|
shape = SubResource("BoxShape3D_g13of")
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
class_name PlayerCamera extends Node
|
class_name PlayerCamera extends Node
|
||||||
|
|
||||||
const CAMERA_PIXELS_PER_UNIT = 32.0
|
const CAMERA_PIXELS_PER_UNIT = 1.0
|
||||||
const CAMERA_PIXEL_SCALE = 1.0
|
const CAMERA_PIXEL_SCALE = 2.0
|
||||||
|
|
||||||
@export var camera:Camera3D = null
|
@export var camera:Camera3D = null
|
||||||
@export var target:Node3D = null
|
@export var target:Node3D = null
|
||||||
|
@export var offset:Vector3 = Vector3(0, 0, 16)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
# I tried a few things but this is most consistent for both backbuffer and
|
# I tried a few things but this is most consistent for both backbuffer and
|
||||||
@@ -18,7 +19,7 @@ func _process(delta: float) -> void:
|
|||||||
) / unitScale;
|
) / unitScale;
|
||||||
|
|
||||||
var look = target.global_position;
|
var look = target.global_position;
|
||||||
var position = Vector3(0, 0, 2) + look;
|
var position = offset + look;
|
||||||
|
|
||||||
camera.look_at_from_position(
|
camera.look_at_from_position(
|
||||||
Vector3(position.x, position.y + z, position.z),
|
Vector3(position.x, position.y + z, position.z),
|
||||||
|
13
entities/player/PlayerMaterial.tres
Normal file
13
entities/player/PlayerMaterial.tres
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://cv8q4cbjyfauh"]
|
||||||
|
|
||||||
|
[ext_resource type="Shader" uid="uid://b3vi5kwotike5" path="res://materials/EntityMaterialShader.gdshader" id="1_gsq3s"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entities/player/Player.png" id="2_awgof"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
render_priority = 0
|
||||||
|
shader = ExtResource("1_gsq3s")
|
||||||
|
shader_parameter/text = ExtResource("2_awgof")
|
||||||
|
shader_parameter/tileColumnCount = 4
|
||||||
|
shader_parameter/tileRowCount = 1
|
||||||
|
shader_parameter/tile = 0
|
||||||
|
shader_parameter/color = Color(1, 1, 1, 1)
|
@@ -1,47 +1,121 @@
|
|||||||
class_name PlayerMovement extends Node
|
class_name PlayerMovement extends Node
|
||||||
|
|
||||||
const TURN_SPEED = 30.0
|
const SPEED = 64.0
|
||||||
const SPEED = 8.0
|
const FRICTION = 0.01
|
||||||
|
|
||||||
|
enum FacingDirection {
|
||||||
|
SOUTH = 0,
|
||||||
|
EAST = 1,
|
||||||
|
NORTH = 2,
|
||||||
|
WEST = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
const FacingDirWalkAnimations = {
|
||||||
|
FacingDirection.SOUTH: "walk_south",
|
||||||
|
FacingDirection.EAST: "walk_east",
|
||||||
|
FacingDirection.NORTH: "walk_north",
|
||||||
|
FacingDirection.WEST: "walk_west"
|
||||||
|
};
|
||||||
|
|
||||||
@export var player:CharacterBody3D
|
@export var player:CharacterBody3D
|
||||||
|
@export var rotated:Node3D
|
||||||
|
@export var sprite:AnimatedSprite3D
|
||||||
|
|
||||||
|
var facingDir:FacingDirection = FacingDirection.SOUTH
|
||||||
var inputDir:Vector2 = Vector2.ZERO
|
var inputDir:Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
|
func _enter_tree() -> void:
|
||||||
|
if !sprite:
|
||||||
|
return
|
||||||
|
for dir in FacingDirWalkAnimations:
|
||||||
|
if sprite.animation != FacingDirWalkAnimations[dir]:
|
||||||
|
continue
|
||||||
|
facingDir = dir
|
||||||
|
break
|
||||||
|
|
||||||
func canMove() -> bool:
|
func canMove() -> bool:
|
||||||
if PAUSE.isMovementPaused():
|
if PAUSE.isMovementPaused():
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
func applyFacingDir() -> void:
|
||||||
|
if !sprite || inputDir.length() <= 0.01:
|
||||||
|
return
|
||||||
|
|
||||||
|
if inputDir.y > 0:
|
||||||
|
if facingDir != FacingDirection.NORTH && inputDir.x != 0:
|
||||||
|
if inputDir.x > 0 && facingDir == FacingDirection.EAST:
|
||||||
|
facingDir = FacingDirection.EAST
|
||||||
|
elif inputDir.x < 0 && facingDir == FacingDirection.WEST:
|
||||||
|
facingDir = FacingDirection.WEST
|
||||||
|
else:
|
||||||
|
facingDir = FacingDirection.NORTH
|
||||||
|
else:
|
||||||
|
facingDir = FacingDirection.NORTH
|
||||||
|
elif inputDir.y < 0:
|
||||||
|
if facingDir != FacingDirection.SOUTH && inputDir.x != 0:
|
||||||
|
if inputDir.x > 0 && facingDir == FacingDirection.EAST:
|
||||||
|
facingDir = FacingDirection.EAST
|
||||||
|
elif inputDir.x < 0 && facingDir == FacingDirection.WEST:
|
||||||
|
facingDir = FacingDirection.WEST
|
||||||
|
else:
|
||||||
|
facingDir = FacingDirection.SOUTH
|
||||||
|
else:
|
||||||
|
facingDir = FacingDirection.SOUTH
|
||||||
|
elif inputDir.x > 0:
|
||||||
|
facingDir = FacingDirection.EAST
|
||||||
|
else:
|
||||||
|
facingDir = FacingDirection.WEST
|
||||||
|
|
||||||
|
sprite.animation = FacingDirWalkAnimations[facingDir]
|
||||||
|
|
||||||
|
func applyGravity() -> void:
|
||||||
|
if !player.is_on_floor():
|
||||||
|
player.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||||
|
|
||||||
|
func applyMovement() -> void:
|
||||||
|
if !canMove():
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
# Use camera orientation for movement direction
|
||||||
|
var cam_basis = get_viewport().get_camera_3d().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()
|
||||||
|
|
||||||
|
var directionAdjusted = (
|
||||||
|
forward * inputDir.y + right * inputDir.x
|
||||||
|
).normalized()
|
||||||
|
if directionAdjusted.length() <= 0.01:
|
||||||
|
return
|
||||||
|
|
||||||
|
if rotated:
|
||||||
|
var targetRot = atan2(directionAdjusted.x, directionAdjusted.z)
|
||||||
|
rotated.rotation.y = targetRot
|
||||||
|
|
||||||
|
player.velocity.x = directionAdjusted.x * SPEED
|
||||||
|
player.velocity.z = directionAdjusted.z * SPEED
|
||||||
|
|
||||||
|
func applyFriction(delta:float) -> void:
|
||||||
|
player.velocity.x *= delta * FRICTION
|
||||||
|
player.velocity.z *= delta * FRICTION
|
||||||
|
|
||||||
func _physics_process(delta:float) -> void:
|
func _physics_process(delta:float) -> void:
|
||||||
|
if !player:
|
||||||
|
return
|
||||||
|
|
||||||
var cameraCurrent = get_viewport().get_camera_3d()
|
var cameraCurrent = get_viewport().get_camera_3d()
|
||||||
if !cameraCurrent:
|
if !cameraCurrent:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Player movement
|
applyGravity()
|
||||||
var directionAdjusted = Vector3.ZERO
|
applyFriction(delta)
|
||||||
if canMove():
|
applyMovement()
|
||||||
# Use camera orientation for movement direction
|
applyFacingDir()
|
||||||
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()
|
player.move_and_slide()
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://d0ywgijpuqy0r"]
|
[gd_scene load_steps=4 format=3 uid="uid://d0ywgijpuqy0r"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cluuhtfjeodwb" path="res://maps/TestMapBase.tscn" id="1_ox0si"]
|
[ext_resource type="PackedScene" uid="uid://cluuhtfjeodwb" path="res://maps/TestMapBase.tscn" id="1_ox0si"]
|
||||||
[ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://entities/player/Player.tscn" id="2_0d2qr"]
|
[ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://entities/player/Player.tscn" id="2_0d2qr"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://kabs7mopalmo" path="res://entities/npc/NPC.tscn" id="3_0vfw4"]
|
||||||
|
|
||||||
[node name="TestMap" type="Node3D"]
|
[node name="TestMap" type="Node3D"]
|
||||||
|
|
||||||
@@ -9,3 +10,6 @@
|
|||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource("2_0d2qr")]
|
[node name="Player" parent="." instance=ExtResource("2_0d2qr")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.59, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.59, 0)
|
||||||
|
|
||||||
|
[node name="NPC" parent="." instance=ExtResource("3_0vfw4")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.33181, 0.554601, 0.508184)
|
||||||
|
@@ -3,10 +3,10 @@
|
|||||||
[ext_resource type="Material" uid="uid://chuogedj81c5" path="res://materials/WorldMaterial.tres" id="1_x4ibw"]
|
[ext_resource type="Material" uid="uid://chuogedj81c5" path="res://materials/WorldMaterial.tres" id="1_x4ibw"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_owt5q"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_owt5q"]
|
||||||
size = Vector2(10, 10)
|
size = Vector2(200, 200)
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_x4ibw"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_x4ibw"]
|
||||||
size = Vector3(10, 0.1, 10)
|
size = Vector3(200, 0.1, 200)
|
||||||
|
|
||||||
[node name="TestMapBase" type="Node3D"]
|
[node name="TestMapBase" type="Node3D"]
|
||||||
|
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://bx0778wr1ge00"]
|
|
||||||
|
|
||||||
[ext_resource type="Shader" uid="uid://be6ueh411xro5" path="res://materials/WorldMaterialShader.gdshader" id="1_h67lk"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://cu1hvpqmqn31n" path="res://icon.svg" id="2_7766c"]
|
|
||||||
|
|
||||||
[resource]
|
|
||||||
render_priority = 0
|
|
||||||
shader = ExtResource("1_h67lk")
|
|
||||||
shader_parameter/text = ExtResource("2_7766c")
|
|
@@ -7,3 +7,4 @@
|
|||||||
render_priority = 0
|
render_priority = 0
|
||||||
shader = ExtResource("1_76gxt")
|
shader = ExtResource("1_76gxt")
|
||||||
shader_parameter/text = ExtResource("2_7os1f")
|
shader_parameter/text = ExtResource("2_7os1f")
|
||||||
|
shader_parameter/color = Color(1, 1, 1, 1)
|
||||||
|
@@ -2,6 +2,7 @@ shader_type spatial;
|
|||||||
render_mode unshaded;
|
render_mode unshaded;
|
||||||
|
|
||||||
uniform sampler2D text;
|
uniform sampler2D text;
|
||||||
|
uniform vec4 color: source_color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
//void vertex() {
|
//void vertex() {
|
||||||
//
|
//
|
||||||
@@ -9,6 +10,6 @@ uniform sampler2D text;
|
|||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
vec4 tex_color = texture(text, UV);
|
vec4 tex_color = texture(text, UV);
|
||||||
ALBEDO = tex_color.rgb;
|
ALBEDO = tex_color.rgb * color.rgb;
|
||||||
ALPHA = tex_color.a;
|
ALPHA = tex_color.a * color.a;
|
||||||
}
|
}
|
Reference in New Issue
Block a user