summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--character/fps_controller/fps_controller.gd58
-rw-r--r--character/fps_controller/fps_controller.tscn20
-rw-r--r--export_presets.cfg0
-rw-r--r--project.godot38
-rw-r--r--singletons/settings.gd3
5 files changed, 119 insertions, 0 deletions
diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd
new file mode 100644
index 0000000..e5f119b
--- /dev/null
+++ b/character/fps_controller/fps_controller.gd
@@ -0,0 +1,58 @@
+extends KinematicBody
+
+onready var camera = $Camera
+onready var ray = $Camera/RayCast
+
+export var walk_speed : int = 5
+export var accel : float = 0.2
+export var gravity : int = -1
+export var term_velocity : int = -35
+
+var velocity : Vector3
+
+func _ready():
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+
+func _process(_delta):
+ get_input()
+
+func _physics_process(_delta):
+ handle_movement()
+
+func get_input():
+ var dir : Vector3 = Vector3.ZERO
+
+ #Get base movement input
+
+ if Input.is_action_pressed("forward"):
+ dir += -global_transform.basis.z
+ if Input.is_action_pressed("backward"):
+ dir += global_transform.basis.z
+ if Input.is_action_pressed("left"):
+ dir += -global_transform.basis.x
+ if Input.is_action_pressed("right"):
+ dir += global_transform.basis.x
+
+ dir = dir.normalized()
+
+ #Pull X and Z values from directional input. Velocity.y will be handled in physics loop
+
+ velocity.x = lerp(velocity.x, dir.x * walk_speed, accel)
+ velocity.z = lerp(velocity.z, dir.z * walk_speed, accel)
+
+func handle_movement():
+ #Apply gravity
+ velocity.y += gravity
+ if velocity.y < term_velocity:
+ velocity.y = term_velocity
+
+ velocity = move_and_slide(velocity, Vector3.UP)
+
+func _input(event):
+ #Handle mouse movement for camera
+ if event is InputEventMouseMotion:
+ self.rotate_y(-event.relative.x * Settings.mouse_sens)
+ camera.rotate_x(-event.relative.y * Settings.mouse_sens)
+ camera.rotation.x = clamp(camera.rotation.x, -1.2, 1.2)
+
+
diff --git a/character/fps_controller/fps_controller.tscn b/character/fps_controller/fps_controller.tscn
new file mode 100644
index 0000000..c0009d5
--- /dev/null
+++ b/character/fps_controller/fps_controller.tscn
@@ -0,0 +1,20 @@
+[gd_scene load_steps=3 format=2]
+
+[ext_resource path="res://character/fps_controller/fps_controller.gd" type="Script" id=1]
+
+[sub_resource type="CapsuleShape" id=1]
+radius = 0.3
+
+[node name="fps_controller" type="KinematicBody"]
+script = ExtResource( 1 )
+
+[node name="CollisionShape" type="CollisionShape" parent="."]
+transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0 )
+shape = SubResource( 1 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.796127, 0 )
+
+[node name="RayCast" type="RayCast" parent="Camera"]
+cast_to = Vector3( 0, 0, -3 )
+collision_mask = 2
diff --git a/export_presets.cfg b/export_presets.cfg
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/export_presets.cfg
diff --git a/project.godot b/project.godot
index b1f7083..4db74bd 100644
--- a/project.godot
+++ b/project.godot
@@ -13,14 +13,52 @@ config_version=4
config/name="Game Jam 49"
config/icon="res://icon.png"
+[autoload]
+
+Settings="*res://singletons/settings.gd"
+
[gui]
common/drop_mouse_on_gui_input_disabled=true
+[input]
+
+forward={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
+ ]
+}
+backward={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
+ ]
+}
+right={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
+ ]
+}
+interact={
+"deadzone": 0.5,
+"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":false,"script":null)
+ ]
+}
+left={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
+ ]
+}
+
[physics]
common/enable_pause_aware_picking=true
[rendering]
+quality/driver/driver_name="GLES2"
environment/default_environment="res://default_env.tres"
diff --git a/singletons/settings.gd b/singletons/settings.gd
new file mode 100644
index 0000000..bc8bfe0
--- /dev/null
+++ b/singletons/settings.gd
@@ -0,0 +1,3 @@
+extends Node
+
+var mouse_sens : float = 0.003