I found (somewhere) and am using the following function to get the ground (Y) position at a particular location (X,Z)...
Using it to teleport sometimes spawns one into rock formations.Code:Vector3 GetGroundPosition(Vector3 sourcePos) { LayerMask GROUND_MASKS = LayerMask.GetMask("Terrain", "World", "Construction"); RaycastHit hitInfo; if (Physics.Raycast(sourcePos, Vector3.down, out hitInfo, GROUND_MASKS)) sourcePos.y = hitInfo.point.y; sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos)); return sourcePos; }
Does anyone know how to fix it or have a better way?
Short of dropping the player from the sky I have no idea how to prevent this.
Getting proper ground position?
Discussion in 'Rust Development' started by carny666, Dec 15, 2017.
-
Not sure, but you can remove check for LayerMask and RayCast will hit first object that he will found.
-
Well there you have it. Thanks friend.