summaryrefslogtreecommitdiffstats
path: root/character
diff options
context:
space:
mode:
authormikatomik <mikec_2007@hotmail.com>2022-09-12 07:16:49 -0400
committermikatomik <mikec_2007@hotmail.com>2022-09-15 01:42:17 -0400
commitb058fcbca09c3b20b84ec96ec75b4d63ef4c1eda (patch)
tree5dbf67f822fd827cd01ccf2c40de3878c4821d74 /character
parent53e8605d35774aac8a9fe6abe04f8e38b53f3866 (diff)
downloadgodot_wildjam_49-b058fcbca09c3b20b84ec96ec75b4d63ef4c1eda.tar.gz
godot_wildjam_49-b058fcbca09c3b20b84ec96ec75b4d63ef4c1eda.zip
Import ladder and config FPS to climb it
Diffstat (limited to 'character')
-rw-r--r--character/fps_controller/fps_controller.gd34
-rw-r--r--character/fps_controller/fps_controller.tscn14
2 files changed, 36 insertions, 12 deletions
diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd
index 9c4e7c3..ecd8871 100644
--- a/character/fps_controller/fps_controller.gd
+++ b/character/fps_controller/fps_controller.gd
@@ -2,6 +2,7 @@ extends KinematicBody
onready var camera = $Camera
onready var ray = $Camera/RayCast
+onready var ladder_area = $ladder_detector
export var walk_speed : int = 10
export var accel : float = 0.2
@@ -11,14 +12,7 @@ export var jump_strength : int = 20
export var inertia : int = 5
var velocity : Vector3
-
-var state = WALKING
-
-enum {
- WALKING,
- SPRINTING,
-}
-
+var is_climbing : bool = false
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
@@ -38,8 +32,12 @@ func get_input():
if Input.is_action_pressed("forward"):
dir += -global_transform.basis.z
+ if is_climbing:
+ dir += global_transform.basis.y
if Input.is_action_pressed("backward"):
dir += global_transform.basis.z
+ if is_climbing:
+ dir += -global_transform.basis.y
if Input.is_action_pressed("left"):
dir += -global_transform.basis.x
if Input.is_action_pressed("right"):
@@ -49,14 +47,18 @@ func get_input():
#Pull X and Z values from directional input. Velocity.y will be handled in physics loop
+ if is_climbing:
+ velocity.y = lerp(velocity.y, dir.y * walk_speed, accel)
+
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
+ if !is_climbing:
+ velocity.y += gravity
+ if velocity.y < term_velocity:
+ velocity.y = term_velocity
velocity = move_and_slide(velocity, Vector3.UP, true, 4, PI/4, false)
@@ -83,3 +85,13 @@ func handle_collision():
# So to add force at collision position, substract colliders pos from collision.position
var col_pos = collision.position - collider.transform.origin
collider.add_force(col_force_vec, col_pos)
+
+
+func _on_ladder_detector_body_entered(body):
+ if body.is_in_group("ladder"):
+ is_climbing = true
+
+
+func _on_ladder_detector_body_exited(body):
+ if body.is_in_group("ladder"):
+ is_climbing = false
diff --git a/character/fps_controller/fps_controller.tscn b/character/fps_controller/fps_controller.tscn
index c176a39..d1bf6be 100644
--- a/character/fps_controller/fps_controller.tscn
+++ b/character/fps_controller/fps_controller.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=4 format=2]
[ext_resource path="res://character/fps_controller/fps_controller.gd" type="Script" id=1]
@@ -6,6 +6,9 @@
radius = 0.3
height = 2.0
+[sub_resource type="CapsuleShape" id=2]
+radius = 0.374691
+
[node name="fps_controller" type="KinematicBody"]
script = ExtResource( 1 )
@@ -20,3 +23,12 @@ far = 5000.0
[node name="RayCast" type="RayCast" parent="Camera"]
cast_to = Vector3( 0, 0, -3 )
collision_mask = 2
+
+[node name="ladder_detector" type="Area" parent="."]
+
+[node name="CollisionShape" type="CollisionShape" parent="ladder_detector"]
+transform = Transform( 1, 0, 0, 0, -1, -8.74228e-08, 0, 8.74228e-08, -1, 0, 0.0169024, -0.58521 )
+shape = SubResource( 2 )
+
+[connection signal="body_entered" from="ladder_detector" to="." method="_on_ladder_detector_body_entered"]
+[connection signal="body_exited" from="ladder_detector" to="." method="_on_ladder_detector_body_exited"]