From 567218d5c7b107083c8e38d5f72a109c314fb7a5 Mon Sep 17 00:00:00 2001 From: dexy Date: Wed, 11 Dec 2019 17:53:34 +1100 Subject: [PATCH] Prevent falling under the map in first person mode --- CodeWalker.Core/World/Entity.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CodeWalker.Core/World/Entity.cs b/CodeWalker.Core/World/Entity.cs index 1304e42..1792752 100644 --- a/CodeWalker.Core/World/Entity.cs +++ b/CodeWalker.Core/World/Entity.cs @@ -161,6 +161,23 @@ namespace CodeWalker.World { Position = coll.HitPos; //hitpos is the end pos if not hit OnGround = false; + + var raydir = new Vector3(0.0f, 0.0f, -1.0f); + var ray = new Ray(Position, raydir); + var rayhit = Space.RayIntersect(ray, float.MaxValue); + if (!rayhit.Hit && rayhit.TestComplete) + { + //must be under the map? try to find the ground... + ray.Position = Position + new Vector3(0.0f, 0.0f, 1000.0f); + rayhit = Space.RayIntersect(ray, float.MaxValue); + if (rayhit.Hit) + { + Position = rayhit.Position + new Vector3(0.0f, 0.0f, Radius) - Center; + OnGround = true; + } + else + { }//didn't find the ground, what to do now? + } } CameraEntity.Position = Position;