From 315df2a10a66b0133c48358de59bd490b5f911be Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 13 Jun 2020 15:30:49 +0200 Subject: [PATCH] Now entities will be snapped to the terrarin after they spawn. --- game/player/Body.gd | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/game/player/Body.gd b/game/player/Body.gd index 5736f584..a49a70a0 100644 --- a/game/player/Body.gd +++ b/game/player/Body.gd @@ -91,6 +91,7 @@ var model_rotation_node : Spatial var character_skeleton : CharacterSkeleton3D var visibility_update_timer : float = 0 +var placed : bool = false func _ready() -> void: camera = get_node_or_null("CameraPivot/Camera") as Camera @@ -177,6 +178,22 @@ func _physics_process(delta : float) -> void: if dead: return + if not placed: + if world != null: + if not world.is_position_walkable(transform.origin): + return + + var space : PhysicsDirectSpaceState = get_world().direct_space_state + + var res : Dictionary = space.intersect_ray(transform.origin, transform.origin + Vector3(0, -100, 0), [ self ]) + + if not res.empty(): + var pos : Vector3 = res["position"] + transform.origin = pos + Vector3(0, 0.2, 0) + + placed = true + return + if entity.c_is_controlled: process_input(delta) process_movement_player(delta)