summaryrefslogtreecommitdiffstats
path: root/character
diff options
context:
space:
mode:
Diffstat (limited to 'character')
-rw-r--r--character/fps_controller/fps_controller.gd15
1 files changed, 15 insertions, 0 deletions
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)