public static float GetGroundLevel(Vector3 position, GroundCheckType _type, LayerMask _layerMask) { if (_type == GroundCheckType.NONE) { return(position.y); } Vector3 pos = position; pos.y = 1000; if (_type == GroundCheckType.RAYCAST) { RaycastHit hit; if (Physics.Raycast(pos, Vector3.down, out hit, Mathf.Infinity, _layerMask.value)) { position.y = hit.point.y; } } else { position.y = Terrain.activeTerrain.SampleHeight(position); } return(position.y); }
public static float GetGroundLevel(Vector3 _position, GroundCheckType _type, LayerMask _layerMask, float _min_offset = 0.5f, float _max_offset = 1000, float _base_offset = 0) { if (_type == GroundCheckType.NONE) { return(_position.y); } if (_type == GroundCheckType.RAYCAST) { RaycastHit hit; if (Physics.Raycast(new Vector3(_position.x, _position.y + _min_offset + (_base_offset * -1), _position.z), Vector3.down, out hit, Mathf.Infinity, _layerMask, WorldManager.TriggerInteraction)) { _position.y = hit.point.y; } else if (Physics.Raycast(new Vector3(_position.x, _position.y + _max_offset + (_base_offset * -1), _position.z), Vector3.down, out hit, Mathf.Infinity, _layerMask, WorldManager.TriggerInteraction)) { _position.y = hit.point.y; } else if (Terrain.activeTerrain != null) { _position.y = Terrain.activeTerrain.SampleHeight(_position) + Terrain.activeTerrain.transform.position.y; } } else if (Terrain.activeTerrain != null) { _position.y = Terrain.activeTerrain.SampleHeight(_position) + Terrain.activeTerrain.transform.position.y; } return(_position.y); }