Rendering how I want for now
This commit is contained in:
@@ -2,82 +2,20 @@
|
||||
class_name EntityMovement extends Node
|
||||
|
||||
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"
|
||||
};
|
||||
|
||||
const FacingDirAngle = {
|
||||
FacingDirection.SOUTH: 0.0,
|
||||
FacingDirection.EAST: PI / 2,
|
||||
FacingDirection.NORTH: PI,
|
||||
FacingDirection.WEST: -PI / 2
|
||||
};
|
||||
const WALK_SPEED_DEFAULT = 8
|
||||
const RUN_SPEED_DEFAULT = 12
|
||||
|
||||
var _inputDir:Vector2 = Vector2.ZERO
|
||||
var _facingDir:FacingDirection = FacingDirection.SOUTH
|
||||
var _running:bool = false
|
||||
|
||||
@export var body:CharacterBody3D
|
||||
@export var rotate:Node3D
|
||||
@export var sprite:AnimatedSprite3D
|
||||
@export var walkSpeed:float = 48.0
|
||||
@export var runSpeed:float = 64.0
|
||||
@export var facingDir:FacingDirection = FacingDirection.SOUTH:
|
||||
set(value):
|
||||
_facingDir = value
|
||||
_updateSprite()
|
||||
get:
|
||||
return _facingDir
|
||||
@export var walkSpeed:float = WALK_SPEED_DEFAULT
|
||||
@export var runSpeed:float = RUN_SPEED_DEFAULT
|
||||
|
||||
#
|
||||
# Private Methods
|
||||
#
|
||||
func _updateSprite() -> void:
|
||||
if !sprite || sprite.animation == FacingDirWalkAnimations[facingDir]:
|
||||
return
|
||||
sprite.animation = FacingDirWalkAnimations[facingDir]
|
||||
|
||||
|
||||
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
|
||||
|
||||
func _applyGravity() -> void:
|
||||
if !body.is_on_floor():
|
||||
body.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||
@@ -123,7 +61,7 @@ func _applyFriction(delta:float) -> void:
|
||||
body.velocity.z *= delta * FRICTION
|
||||
|
||||
#
|
||||
# Protected Methods
|
||||
# Protected Methods
|
||||
#
|
||||
func canMove() -> bool:
|
||||
return true
|
||||
@@ -132,7 +70,7 @@ func canMove() -> bool:
|
||||
# Callbacks
|
||||
#
|
||||
func _enter_tree() -> void:
|
||||
_updateSprite()
|
||||
pass
|
||||
|
||||
func _physics_process(delta:float) -> void:
|
||||
if Engine.is_editor_hint():
|
||||
@@ -144,5 +82,4 @@ func _physics_process(delta:float) -> void:
|
||||
_applyGravity()
|
||||
_applyFriction(delta)
|
||||
_applyMovement()
|
||||
_applyFacingDir()
|
||||
body.move_and_slide()
|
||||
|
||||
@@ -3,15 +3,6 @@ class_name NPC extends CharacterBody3D
|
||||
|
||||
@export var _movement:NPCMovement
|
||||
|
||||
@export var facingDirection:EntityMovement.FacingDirection:
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.facingDir = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.facingDir
|
||||
return EntityMovement.FacingDirection.SOUTH
|
||||
|
||||
@export var walkSpeed:float = 48.0:
|
||||
set(value):
|
||||
if _movement:
|
||||
|
||||
@@ -1,96 +1,48 @@
|
||||
[gd_scene load_steps=12 format=3 uid="uid://kabs7mopalmo"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://kabs7mopalmo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://crw7ls7t8cwct" path="res://entity/npc/NPC.gd" id="1_00k55"]
|
||||
[ext_resource type="Script" uid="uid://b00rxpveu3v4m" path="res://InteractableArea.gd" id="2_x8luf"]
|
||||
[ext_resource type="Script" uid="uid://tlfthv88ki0y" path="res://entity/npc/NPCMovement.gd" id="3_1seh5"]
|
||||
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entity/player/Player.png" id="4_x8luf"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1seh5"]
|
||||
size = Vector3(16, 16, 16)
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_jphom"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rl6fg"]
|
||||
atlas = ExtResource("4_x8luf")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_jphom"]
|
||||
size = Vector3(1, 2, 1)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_q57vx"]
|
||||
atlas = ExtResource("4_x8luf")
|
||||
region = Rect2(48, 0, 16, 16)
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jphom"]
|
||||
shading_mode = 0
|
||||
|
||||
[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
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_jphom"]
|
||||
material = SubResource("StandardMaterial3D_jphom")
|
||||
|
||||
[node name="NPC" type="CharacterBody3D" node_paths=PackedStringArray("_movement")]
|
||||
script = ExtResource("1_00k55")
|
||||
facingDirection = null
|
||||
walkSpeed = null
|
||||
runSpeed = null
|
||||
_movement = NodePath("Scripts/NPCMovement")
|
||||
|
||||
[node name="Scripts" type="Node" parent="."]
|
||||
|
||||
[node name="NPCMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("body", "sprite")]
|
||||
[node name="NPCMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("body")]
|
||||
script = ExtResource("3_1seh5")
|
||||
body = NodePath("../..")
|
||||
sprite = NodePath("../../AnimatedSprite3D")
|
||||
|
||||
[node name="InteractableArea" type="Area3D" parent="."]
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_jphom")
|
||||
|
||||
[node name="Rotate" type="Node3D" parent="."]
|
||||
|
||||
[node name="InteractableArea" type="Area3D" parent="Rotate"]
|
||||
script = ExtResource("2_x8luf")
|
||||
metadata/_custom_type_script = "uid://b00rxpveu3v4m"
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractableArea"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 0)
|
||||
shape = SubResource("BoxShape3D_1seh5")
|
||||
[node name="InteractableShape" type="CollisionShape3D" parent="Rotate/InteractableArea"]
|
||||
transform = Transform3D(0.999999, -0.000856732, 0.0007724, 0.000857588, 0.999999, -0.00114162, -0.000771449, 0.00114226, 0.999999, 0, 0, 0)
|
||||
shape = SubResource("BoxShape3D_jphom")
|
||||
|
||||
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
|
||||
pixel_size = 1.0
|
||||
axis = 1
|
||||
double_sided = false
|
||||
texture_filter = 0
|
||||
sprite_frames = SubResource("SpriteFrames_1seh5")
|
||||
animation = &"walk_south"
|
||||
[node name="CapsuleMesh" type="MeshInstance3D" parent="Rotate"]
|
||||
mesh = SubResource("CapsuleMesh_jphom")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8.5, 0)
|
||||
shape = SubResource("SphereShape3D_x8luf")
|
||||
|
||||
[connection signal="interactEvent" from="InteractableArea" to="." method="onInteract"]
|
||||
[connection signal="interactEvent" from="Rotate/InteractableArea" to="." method="onInteract"]
|
||||
|
||||
@@ -3,29 +3,20 @@ class_name Player extends CharacterBody3D
|
||||
|
||||
@export var _movement:PlayerMovement
|
||||
|
||||
@export var facingDirection:EntityMovement.FacingDirection:
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.facingDir = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.facingDir
|
||||
return EntityMovement.FacingDirection.SOUTH
|
||||
|
||||
@export var walkSpeed:float = 48.0:
|
||||
@export var walkSpeed:float = EntityMovement.WALK_SPEED_DEFAULT:
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.walkSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.walkSpeed
|
||||
return 48.0
|
||||
return EntityMovement.WALK_SPEED_DEFAULT
|
||||
|
||||
@export var runSpeed:float = 64.0:
|
||||
@export var runSpeed:float = EntityMovement.RUN_SPEED_DEFAULT:
|
||||
set(value):
|
||||
if _movement:
|
||||
_movement.runSpeed = value
|
||||
get:
|
||||
if _movement:
|
||||
return _movement.runSpeed
|
||||
return 64.0
|
||||
return EntityMovement.RUN_SPEED_DEFAULT
|
||||
|
||||
@@ -1,68 +1,29 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://2ch34sio36nv"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://2ch34sio36nv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ylmy3nvpirgr" path="res://entity/player/Player.gd" id="1_24gqh"]
|
||||
[ext_resource type="Script" uid="uid://bwxdv3kxrs4oj" path="res://entity/player/PlayerMovement.gd" id="2_o7et6"]
|
||||
[ext_resource type="Script" uid="uid://b3nty7pvbo58d" path="res://entity/player/PlayerInteraction.gd" id="3_24gqh"]
|
||||
[ext_resource type="Script" uid="uid://bdv1fj1pwknrs" path="res://entity/player/PlayerInput.gd" id="4_yjynp"]
|
||||
[ext_resource type="Script" uid="uid://bdjgvyiacbg28" path="res://entity/player/PlayerCamera.gd" id="5_g3lhm"]
|
||||
[ext_resource type="Texture2D" uid="uid://xx3qp5xh7tgu" path="res://entity/player/Player.png" id="7_fmb3c"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_4pwj0"]
|
||||
radius = 8.5
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_rykwh"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_rl6fg"]
|
||||
atlas = ExtResource("7_fmb3c")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rykwh"]
|
||||
shading_mode = 0
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_q57vx"]
|
||||
atlas = ExtResource("7_fmb3c")
|
||||
region = Rect2(48, 0, 16, 16)
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_etv1g"]
|
||||
material = SubResource("StandardMaterial3D_rykwh")
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ak4un"]
|
||||
atlas = ExtResource("7_fmb3c")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_etv1g"]
|
||||
shading_mode = 0
|
||||
albedo_color = Color(0.376471, 1, 1, 1)
|
||||
|
||||
[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="BoxMesh" id="BoxMesh_m44ds"]
|
||||
material = SubResource("StandardMaterial3D_etv1g")
|
||||
size = Vector3(0.4, 0.4, 0.4)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_g13of"]
|
||||
size = Vector3(10, 16, 8)
|
||||
size = Vector3(1.14069, 1, 1.38867)
|
||||
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_movement")]
|
||||
script = ExtResource("1_24gqh")
|
||||
@@ -70,15 +31,14 @@ _movement = NodePath("Scripts/PlayerMovement")
|
||||
|
||||
[node name="Scripts" type="Node" parent="."]
|
||||
|
||||
[node name="PlayerMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("body", "rotate", "sprite")]
|
||||
[node name="PlayerMovement" type="Node" parent="Scripts" node_paths=PackedStringArray("body", "rotate")]
|
||||
script = ExtResource("2_o7et6")
|
||||
body = NodePath("../..")
|
||||
rotate = NodePath("../../PlayerRotated")
|
||||
sprite = NodePath("../../AnimatedSprite3D")
|
||||
rotate = NodePath("../../PlayerRotate")
|
||||
|
||||
[node name="PlayerInteraction" type="Node" parent="Scripts" node_paths=PackedStringArray("interactableArea", "player")]
|
||||
script = ExtResource("3_24gqh")
|
||||
interactableArea = NodePath("../../PlayerRotated/PlayerInteractableArea")
|
||||
interactableArea = NodePath("../../PlayerRotate/PlayerInteractableArea")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="PlayerInput" type="Node" parent="Scripts" node_paths=PackedStringArray("interaction", "movement")]
|
||||
@@ -92,24 +52,23 @@ camera = NodePath("../../PlayerCamera")
|
||||
target = NodePath("../..")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8.5, 0)
|
||||
shape = SubResource("SphereShape3D_4pwj0")
|
||||
shape = SubResource("CapsuleShape3D_rykwh")
|
||||
|
||||
[node name="PlayerCamera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, -0.000461383, 0.000263726, 0.000138582, 0.705475, 0.708735, -0.00051305, -0.708735, 0.705475, 0.00619125, 4.26114, 4.36711)
|
||||
|
||||
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0496178, 0, -0.00852585)
|
||||
pixel_size = 1.0
|
||||
axis = 1
|
||||
double_sided = false
|
||||
texture_filter = 0
|
||||
sprite_frames = SubResource("SpriteFrames_2rv2u")
|
||||
animation = &"walk_south"
|
||||
[node name="PlayerRotate" type="Node3D" parent="."]
|
||||
|
||||
[node name="PlayerRotated" type="Node3D" parent="."]
|
||||
[node name="CapsuleMesh" type="MeshInstance3D" parent="PlayerRotate"]
|
||||
mesh = SubResource("CapsuleMesh_etv1g")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="PlayerInteractableArea" type="Area3D" parent="PlayerRotated"]
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="PlayerRotate/CapsuleMesh"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.41166, 0.475431)
|
||||
mesh = SubResource("BoxMesh_m44ds")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerRotated/PlayerInteractableArea"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 10)
|
||||
[node name="PlayerInteractableArea" type="Area3D" parent="PlayerRotate"]
|
||||
|
||||
[node name="InteractHitbox" type="CollisionShape3D" parent="PlayerRotate/PlayerInteractableArea"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0233459, 0, 0.795664)
|
||||
shape = SubResource("BoxShape3D_g13of")
|
||||
|
||||
@@ -6,28 +6,22 @@ const CAMERA_PIXEL_SCALE = 1.0
|
||||
|
||||
@export var camera:Camera3D = null
|
||||
@export var target:Node3D = null
|
||||
@export var offset:Vector3 = Vector3(0, 0, 12)
|
||||
|
||||
var angle = 0.0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if !camera || !target:
|
||||
return
|
||||
|
||||
# Follow target
|
||||
# camera.global_transform.origin = target.global_transform.origin
|
||||
|
||||
# I tried a few things but this is most consistent for both backbuffer and
|
||||
# framebuffer viewports.
|
||||
var viewportHeight = get_viewport().get_visible_rect().size.y;
|
||||
var unitScale = CAMERA_PIXEL_SCALE * CAMERA_PIXELS_PER_UNIT;
|
||||
# # 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
|
||||
|
||||
var z:float = (
|
||||
tan((deg_to_rad(180) - deg_to_rad(camera.fov)) / 2.0) *
|
||||
(viewportHeight / 2.0)
|
||||
) / unitScale;
|
||||
|
||||
var look = target.global_position;
|
||||
var position = offset + look;
|
||||
|
||||
camera.look_at_from_position(
|
||||
Vector3(position.x, position.y + z, position.z),
|
||||
look
|
||||
);
|
||||
|
||||
pass
|
||||
# # Look at target
|
||||
# camera.look_at(target.global_transform.origin, Vector3.UP)
|
||||
|
||||
Reference in New Issue
Block a user