Raycast() public static method

public static Raycast ( Ray ray, RaycastHit &hit, float rayLength, LayerMask layer ) : bool
ray Ray
hit RaycastHit
rayLength float
layer LayerMask
return bool
            public void FixedUpdate()
            {
                foreach (var boid in collection.Boids)
                {
                    if (UPhysics.Raycast(boid.Position, boid.Direction, anticipationDistance))
                    {
                        Debug.DrawLine(boid.Position, boid.Position + anticipationDistance * boid.Direction, Color.red);
                        foreach (var dir in maneuvers)
                        {
                            var globalDir = boid.Rotation * dir;

                            if (!UPhysics.SphereCast(new Ray(boid.Position, globalDir), 1f, maneuverDistance))
                            {
                                Debug.DrawLine(boid.Position, boid.Position + maneuverDistance * globalDir, Color.green);
                                boid.Acceleration += globalDir * intensity;
                                break;
                            }
                            else
                            {
                                Debug.DrawLine(boid.Position, boid.Position + maneuverDistance * globalDir, Color.red);
                            }
                        }
                    }
                    else
                    {
                        Debug.DrawLine(boid.Position, boid.Position + anticipationDistance * boid.Direction, Color.green);
                    }
                }
            }
Esempio n. 2
0
        private object CanBuild(Planner plan, Construction prefab)
        {
            if (prefab.prefabID != 2205372577)
            {
                return(null);
            }
            RaycastHit hit;
            BasePlayer player = plan.GetOwnerPlayer();

            if (permission.UserHasPermission(player.UserIDString, permissionName))
            {
                return(null);
            }
            if (!Physics.Raycast(player.eyes.HeadRay(), out hit, 5f))
            {
                return(null);
            }
            BaseEntity ent = hit.GetEntity();

            if (!ent)
            {
                return(null);
            }
            if (!ent.ShortPrefabName.Contains("external"))
            {
                return(null);
            }
            player.ChatMessage(msg("Deny Crusher", player.UserIDString));
            return(false);
        }
Esempio n. 3
0
        protected virtual void UpdateFocus()
        {
            var direction = (Pivot - Transform.position).normalized;
            var ray       = new Ray(Pivot, direction);

            RaycastHit hit;

            var hasHit = UEPhysics.Raycast(
                ray, out hit, FocusSettings.MaximumDistance, FocusSettings.Layer);

            _focused.Value = hasHit ? hit.transform : null;
        }
        // Calculates the current predicted fall distance based on the predicted landing position
        //      return: The predicted fall distance
        float GetPredictedFallDistance()
        {
            RaycastHit hitInfo;

            if (UnityPhysics.Raycast(new Ray(footWorldPosition, Vector3.down), out hitInfo,
                                     m_GroundingDistance, collisionLayerMask))
            {
                return(hitInfo.distance);
            }

            UpdatePredictedLandingPosition();
            return(m_PredictedLandingPosition == null
                                ? float.MaxValue
                                : footWorldPosition.y - ((Vector3)m_PredictedLandingPosition).y);
        }
Esempio n. 5
0
            public static StorageContainer SpawnContainer(BasePlayer player, int size, bool die)
            {
                var pos = player.transform.position;

                if (die)
                {
                    RaycastHit hit;
                    if (Physics.Raycast(new Ray(player.GetCenter(), Vector3.down), out hit, 1000, rayColl, QueryTriggerInteraction.Ignore))
                    {
                        pos = hit.point;
                    }
                }
                else
                {
                    pos -= new Vector3(0, 100, 0);
                }
                return(SpawnContainer(player, size, pos));
            }
Esempio n. 6
0
        private static T GetLookEntity <T>(BasePlayer player)
        {
            RaycastHit hit;

            if (Physics.Raycast(player.eyes.HeadRay(), out hit) == false)
            {
                return(default(T));
            }

            var entity = hit.GetEntity();

            if (entity == null)
            {
                return(default(T));
            }

            return(entity.GetComponent <T>());
        }
Esempio n. 7
0
        protected virtual float GetUnblockedDistance(float distance)
        {
            if (!WallAvoidanceSettings.AvoidWalls)
            {
                return(distance);
            }

            var direction = (Transform.position - Pivot).normalized;
            var origin    = Pivot + direction * DistanceSettings.Minimum;

            var ray = new Ray(origin, direction);

            RaycastHit hit;

            if (UEPhysics.Raycast(ray, out hit, distance))
            {
                distance =
                    Vector3.Distance(Pivot, hit.point) -
                    WallAvoidanceSettings.MinimumDistance;
            }

            return(distance);
        }
 public bool CastRay(Ray ray, out RaycastHit hit, float maxDistance, int layerMask = UPhysics.AllLayers)
 {
     return(UPhysics.Raycast(ray, out hit, maxDistance, layerMask));
 }