From dff4ca391185726dcc96215fb0ce157ecda032fa Mon Sep 17 00:00:00 2001 From: mikatomik Date: Sun, 11 Sep 2022 23:41:29 -0400 Subject: Begin ship development. Blendfiles added --- character/fps_controller/fps_controller.gd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'character') diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd index 3021d40..e2d4d03 100644 --- a/character/fps_controller/fps_controller.gd +++ b/character/fps_controller/fps_controller.gd @@ -7,9 +7,18 @@ export var walk_speed : int = 5 export var accel : float = 0.2 export var gravity : int = -1 export var term_velocity : int = -35 +export var jump_strength : int = 10 var velocity : Vector3 +var state = WALKING + +enum { + WALKING, + SPRINTING, +} + + func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) @@ -18,6 +27,7 @@ func _process(_delta): func _physics_process(_delta): handle_movement() + handle_jumping() func get_input(): var dir : Vector3 = Vector3.ZERO @@ -55,4 +65,6 @@ func _input(event): camera.rotate_x(-event.relative.y * Settings.mouse_sens) camera.rotation.x = clamp(camera.rotation.x, -1.2, 1.2) - +func handle_jumping(): + if Input.is_action_just_pressed("jump") and is_on_floor(): + velocity.y = jump_strength -- cgit v1.2.3 From 596309d76f30564c32b782439f9c5268ad9afc49 Mon Sep 17 00:00:00 2001 From: mikatomik Date: Mon, 12 Sep 2022 02:31:37 -0400 Subject: Import and configure base model for ship Basic working model of ship, barebones and placeholder textures --- character/fps_controller/fps_controller.gd | 4 ++-- character/fps_controller/fps_controller.tscn | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'character') diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd index e2d4d03..cd49255 100644 --- a/character/fps_controller/fps_controller.gd +++ b/character/fps_controller/fps_controller.gd @@ -3,11 +3,11 @@ extends KinematicBody onready var camera = $Camera onready var ray = $Camera/RayCast -export var walk_speed : int = 5 +export var walk_speed : int = 10 export var accel : float = 0.2 export var gravity : int = -1 export var term_velocity : int = -35 -export var jump_strength : int = 10 +export var jump_strength : int = 20 var velocity : Vector3 diff --git a/character/fps_controller/fps_controller.tscn b/character/fps_controller/fps_controller.tscn index d187121..c176a39 100644 --- a/character/fps_controller/fps_controller.tscn +++ b/character/fps_controller/fps_controller.tscn @@ -4,6 +4,7 @@ [sub_resource type="CapsuleShape" id=1] radius = 0.3 +height = 2.0 [node name="fps_controller" type="KinematicBody"] script = ExtResource( 1 ) @@ -13,7 +14,7 @@ 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 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.30045, 0 ) far = 5000.0 [node name="RayCast" type="RayCast" parent="Camera"] -- cgit v1.2.3 From 4c7622ee9d07671176b37d16902455236265ff68 Mon Sep 17 00:00:00 2001 From: mikatomik Date: Mon, 12 Sep 2022 04:42:12 -0400 Subject: Adjust FPS controller height to better fit scale --- character/fps_controller/fps_controller.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'character') diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd index cd49255..c522e67 100644 --- a/character/fps_controller/fps_controller.gd +++ b/character/fps_controller/fps_controller.gd @@ -56,7 +56,7 @@ func handle_movement(): if velocity.y < term_velocity: velocity.y = term_velocity - velocity = move_and_slide(velocity, Vector3.UP, false, 4, PI/4, false) + velocity = move_and_slide(velocity, Vector3.UP, true, 4, PI/4, false) func _input(event): #Handle mouse movement for camera -- cgit v1.2.3 From 53e8605d35774aac8a9fe6abe04f8e38b53f3866 Mon Sep 17 00:00:00 2001 From: mikatomik Date: Mon, 12 Sep 2022 06:56:30 -0400 Subject: Update FPS controller to play nice with rigid bodies Infinite inertia set to false, the handle_collision func is now individually applying impulses to rigid bodies we collide with so we stop yeeting boxes off the ship just by bumping them or jumping on top of them. --- character/fps_controller/fps_controller.gd | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'character') diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd index c522e67..9c4e7c3 100644 --- a/character/fps_controller/fps_controller.gd +++ b/character/fps_controller/fps_controller.gd @@ -8,6 +8,7 @@ export var accel : float = 0.2 export var gravity : int = -1 export var term_velocity : int = -35 export var jump_strength : int = 20 +export var inertia : int = 5 var velocity : Vector3 @@ -28,6 +29,7 @@ func _process(_delta): func _physics_process(_delta): handle_movement() handle_jumping() + handle_collision() func get_input(): var dir : Vector3 = Vector3.ZERO @@ -68,3 +70,16 @@ func _input(event): func handle_jumping(): if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = jump_strength + +func handle_collision(): + for index in get_slide_count(): + var collision = get_slide_collision(index) + var collider = collision.collider + if (collider.get_class() == "RigidBody"): + var col_force_vec = -collision.normal * inertia # rotate the force along collision normal + # collision pos + # > RigidBody.add_force(force, pos) > The position uses the rotation of the global coordinate system, but is centered at the object's origin. + # > KinematicCollision.position() > The point of collision, in global coordinates. + # 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) -- cgit v1.2.3 From b058fcbca09c3b20b84ec96ec75b4d63ef4c1eda Mon Sep 17 00:00:00 2001 From: mikatomik Date: Mon, 12 Sep 2022 07:16:49 -0400 Subject: Import ladder and config FPS to climb it --- character/fps_controller/fps_controller.gd | 34 +++++++++++++++++++--------- character/fps_controller/fps_controller.tscn | 14 +++++++++++- 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'character') 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"] -- cgit v1.2.3 From f0fe1091639cf6d11d71f292380d613c944221ac Mon Sep 17 00:00:00 2001 From: mikatomik Date: Mon, 12 Sep 2022 07:26:03 -0400 Subject: Fix bug with ladder mat not showing at runtime --- character/fps_controller/fps_controller.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'character') diff --git a/character/fps_controller/fps_controller.gd b/character/fps_controller/fps_controller.gd index ecd8871..09ef556 100644 --- a/character/fps_controller/fps_controller.gd +++ b/character/fps_controller/fps_controller.gd @@ -45,7 +45,7 @@ func get_input(): dir = dir.normalized() - #Pull X and Z values from directional input. Velocity.y will be handled in physics loop + #Pull X and Z values from directional input. Velocity.y will be handled in physics loop unless climbing. if is_climbing: velocity.y = lerp(velocity.y, dir.y * walk_speed, accel) -- cgit v1.2.3