Initial
This commit is contained in:
61
scripts/OverworldEntity.gd
Normal file
61
scripts/OverworldEntity.gd
Normal file
@@ -0,0 +1,61 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
enum Direction {
|
||||
NORTH,
|
||||
SOUTH,
|
||||
WEST,
|
||||
EAST
|
||||
}
|
||||
|
||||
var speed:float = 3200;
|
||||
var friction:float = 7;
|
||||
var gravity:float = 150;
|
||||
|
||||
var direction = Direction.SOUTH;
|
||||
var meshInstance:MeshInstance3D;
|
||||
|
||||
func getDirectionVector() -> Vector3:
|
||||
match direction:
|
||||
Direction.NORTH:
|
||||
return Vector3(0, 0, -1);
|
||||
Direction.SOUTH:
|
||||
return Vector3(0, 0, 1);
|
||||
Direction.WEST:
|
||||
return Vector3(-1, 0, 0);
|
||||
Direction.EAST:
|
||||
return Vector3(1, 0, 0);
|
||||
return Vector3(0, 0, 0);
|
||||
|
||||
# Virtual Methods
|
||||
func updateMovement(delta) -> void:
|
||||
pass
|
||||
|
||||
func updateOverworldLogic(delta) -> void:
|
||||
pass
|
||||
|
||||
# Events
|
||||
func _ready() -> void:
|
||||
meshInstance = get_node("MeshInstance3D")
|
||||
pass
|
||||
|
||||
func _process(delta:float) -> void:
|
||||
# Update logic
|
||||
updateOverworldLogic(delta)
|
||||
|
||||
# Set shader direction.
|
||||
var material:ShaderMaterial = meshInstance.get_surface_override_material(0)
|
||||
material.set_shader_parameter("direction", direction)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Gravity and friction
|
||||
if !is_on_floor():
|
||||
velocity.y -= gravity * delta;
|
||||
else:
|
||||
velocity += -(velocity * friction * delta);
|
||||
|
||||
# Update movement
|
||||
updateMovement(delta)
|
||||
|
||||
# Update character controller.
|
||||
move_and_slide();
|
23
scripts/RosaCamera.gd
Normal file
23
scripts/RosaCamera.gd
Normal file
@@ -0,0 +1,23 @@
|
||||
extends Camera3D
|
||||
|
||||
var PIXEL_SCALE:float = 4.0;
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var z:float = (
|
||||
tan((deg_to_rad(180) - deg_to_rad(fov)) / 2.0) *
|
||||
(get_viewport().size.y / 2.0)
|
||||
) / PIXEL_SCALE;
|
||||
|
||||
var rosa = get_node("..");
|
||||
var look = rosa.position;
|
||||
var position = Vector3(0, 0, 4) + look;
|
||||
look_at_from_position(
|
||||
Vector3(position.x, position.y + z, position.z),
|
||||
look
|
||||
);
|
||||
|
||||
pass
|
50
scripts/RosaController.gd
Normal file
50
scripts/RosaController.gd
Normal file
@@ -0,0 +1,50 @@
|
||||
extends "res://scripts/OverworldEntity.gd"
|
||||
|
||||
var interactRange = 22;
|
||||
|
||||
func updateOverworldLogic(delta) -> void:
|
||||
# Check if interact button is pressed
|
||||
if(Input.is_action_just_pressed("interact")):
|
||||
var rayDirection = getDirectionVector();
|
||||
# cast ray
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.create(
|
||||
position,
|
||||
position + (rayDirection * interactRange)
|
||||
)
|
||||
query.collide_with_areas = true
|
||||
query.exclude = [self]
|
||||
|
||||
var result = get_world_3d().direct_space_state.intersect_ray(query)
|
||||
if result and result.collider:
|
||||
var collider = result.collider
|
||||
if(collider.has_method("interact")):
|
||||
collider.interact(self)
|
||||
|
||||
func updateMovement(delta) -> void:
|
||||
# User movement
|
||||
var dir:Vector2 = Input.get_vector("left", "right", "up", "down");
|
||||
if(dir.x != 0 or dir.y != 0):
|
||||
velocity.x = dir.x * speed * delta;
|
||||
velocity.z = dir.y * speed * delta;
|
||||
|
||||
# Update direction
|
||||
if(dir.x > 0):
|
||||
if(
|
||||
dir.y == 0 or
|
||||
(dir.y < 0 and direction == Direction.SOUTH) or
|
||||
(dir.y > 0 and direction == Direction.NORTH)
|
||||
):
|
||||
direction = Direction.EAST;
|
||||
elif (dir.x < 0):
|
||||
if(
|
||||
dir.y == 0 or
|
||||
(dir.y < 0 and direction == Direction.SOUTH) or
|
||||
(dir.y > 0 and direction == Direction.NORTH)
|
||||
):
|
||||
direction = Direction.WEST;
|
||||
elif (dir.y > 0):
|
||||
direction = Direction.SOUTH;
|
||||
elif (dir.y < 0):
|
||||
direction = Direction.NORTH;
|
||||
pass
|
34
scripts/TestNPCController.gd
Normal file
34
scripts/TestNPCController.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
extends "res://scripts/OverworldEntity.gd"
|
||||
|
||||
func interact(interactor) -> void:
|
||||
print("Hello, I am an NPC!")
|
||||
pass
|
||||
|
||||
func updateMovement(delta) -> void:
|
||||
pass
|
||||
# User movement
|
||||
#var dir:Vector2 = Input.get_vector("left", "right", "up", "down");
|
||||
#if(dir.x != 0 or dir.y != 0):
|
||||
#velocity.x = dir.x * speed * delta;
|
||||
#velocity.z = dir.y * speed * delta;
|
||||
#
|
||||
## Update direction
|
||||
#if(dir.x > 0):
|
||||
#if(
|
||||
#dir.y == 0 or
|
||||
#(dir.y < 0 and direction == Direction.SOUTH) or
|
||||
#(dir.y > 0 and direction == Direction.NORTH)
|
||||
#):
|
||||
#direction = Direction.EAST;
|
||||
#elif (dir.x < 0):
|
||||
#if(
|
||||
#dir.y == 0 or
|
||||
#(dir.y < 0 and direction == Direction.SOUTH) or
|
||||
#(dir.y > 0 and direction == Direction.NORTH)
|
||||
#):
|
||||
#direction = Direction.WEST;
|
||||
#elif (dir.y > 0):
|
||||
#direction = Direction.SOUTH;
|
||||
#elif (dir.y < 0):
|
||||
#direction = Direction.NORTH;
|
||||
#pass
|
Reference in New Issue
Block a user