barebones placeholder character controller
This commit is contained in:
parent
8908b51103
commit
585b642173
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://i5jawm0cwlat"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://i5jawm0cwlat"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Main.gd" id="1_2yjjx"]
|
||||
[ext_resource type="PackedScene" uid="uid://deff7lt34nj0h" path="res://Spaces/Dungeon.tscn" id="2_4gs22"]
|
||||
[ext_resource type="PackedScene" uid="uid://b83k3b5x1wmyl" path="res://Scenes/Player.tscn" id="3_eq7hn"]
|
||||
|
||||
[sub_resource type="Environment" id="Environment_pn2uj"]
|
||||
|
||||
@ -11,8 +12,7 @@ script = ExtResource("1_2yjjx")
|
||||
[node name="Dungeon" parent="." instance=ExtResource("2_4gs22")]
|
||||
visible = false
|
||||
|
||||
[node name="Camera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
[node name="Player" parent="." instance=ExtResource("3_eq7hn")]
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_pn2uj")
|
||||
|
11
Scenes/Player.tscn
Normal file
11
Scenes/Player.tscn
Normal file
@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b83k3b5x1wmyl"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player.gd" id="1_m1g7d"]
|
||||
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("camera")]
|
||||
script = ExtResource("1_m1g7d")
|
||||
camera = NodePath("Pivot/Camera3D")
|
||||
|
||||
[node name="Pivot" type="Node3D" parent="."]
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Pivot"]
|
@ -3,9 +3,9 @@ extends Node3D
|
||||
|
||||
func _ready():
|
||||
add_child($Dungeon.generate_geometry())
|
||||
$Camera.position = $Dungeon.get_spawn_point()
|
||||
$Camera.position.y += 0.5
|
||||
$Player.position = $Dungeon.get_spawn_point()
|
||||
$Player.position.y += 0.5
|
||||
|
||||
|
||||
func _process(delta):
|
||||
$Camera.rotate_y(0.01)
|
||||
pass
|
||||
|
64
Scripts/Player.gd
Normal file
64
Scripts/Player.gd
Normal file
@ -0,0 +1,64 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
|
||||
@export var camera: Camera3D
|
||||
|
||||
const VIEW_BOB_FREQUENCY = 8
|
||||
const VIEW_BOB_AMPLITUDE = 0.03
|
||||
|
||||
var speed := 2
|
||||
var turn_speed_sec := 0.1
|
||||
var turn_degrees := 90
|
||||
var view_bob_time := 0.0 # increased while velocity is not zero
|
||||
|
||||
|
||||
func _get_input() -> Vector3:
|
||||
var input_dir := Vector3()
|
||||
|
||||
if Input.is_action_pressed("move_forward"):
|
||||
input_dir -= global_transform.basis.z
|
||||
if Input.is_action_pressed("move_backward"):
|
||||
input_dir += global_transform.basis.z
|
||||
|
||||
return input_dir.normalized()
|
||||
|
||||
|
||||
func _process_view_bobbing(delta: float) -> void:
|
||||
view_bob_time += delta * velocity.length()
|
||||
camera.position.y = sin(view_bob_time * VIEW_BOB_FREQUENCY) * VIEW_BOB_AMPLITUDE
|
||||
camera.position.x = cos(view_bob_time * (VIEW_BOB_FREQUENCY / 2)) * VIEW_BOB_AMPLITUDE
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("turn_left"):
|
||||
create_tween().tween_property(
|
||||
self,
|
||||
"rotation_degrees:y",
|
||||
rotation_degrees.y + turn_degrees,
|
||||
turn_speed_sec
|
||||
)
|
||||
if event.is_action_pressed("turn_right"):
|
||||
create_tween().tween_property(
|
||||
self,
|
||||
"rotation_degrees:y",
|
||||
rotation_degrees.y - turn_degrees,
|
||||
turn_speed_sec
|
||||
)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_process_view_bobbing(delta)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# TODO
|
||||
#velocity.y += gravity * delta
|
||||
var final_velocity = _get_input() * speed
|
||||
|
||||
velocity.x = final_velocity.x
|
||||
velocity.z = final_velocity.z
|
||||
move_and_slide()
|
@ -19,6 +19,33 @@ config/icon="res://icon.svg"
|
||||
|
||||
enabled=PackedStringArray()
|
||||
|
||||
[input]
|
||||
|
||||
move_forward={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_backward={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
turn_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
turn_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
|
Loading…
Reference in New Issue
Block a user