UnityEngine.Debug.DrawRay(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Color, float, bool)

Here are the examples of the csharp api UnityEngine.Debug.DrawRay(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Color, float, bool) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

9 Examples 7

19 View Source File : EnemyBossScript.cs
License : MIT License
Project Creator : HDNua

bool UpdateLanding()
    {
        RaycastHit2D rayB = Physics2D.Raycast(groundCheckBack.position, Vector2.down, groundCheckRadius, _whatIsGround);
        RaycastHit2D rayF = Physics2D.Raycast(groundCheckFront.position, Vector2.down, groundCheckRadius, _whatIsGround);

        Debug.DrawRay(groundCheckBack.position, Vector2.down, Color.red);
        Debug.DrawRay(groundCheckFront.position, Vector2.down, Color.red);

        if (Handy.DebugPoint) // PlayerController.UpdateLanding
        {
            Handy.Log("PlayerController.UpdateLanding");
        }

        if (OnGround())
        {
            // 절차:
            // 1. 캐릭터에서 수직으로 내린 직선에 맞는 경사면의 법선 벡터를 구한다.
            // 2. 법선 벡터와 이동 방향 벡터가 이루는 각도가 예각이면 내려오는 것
            //    법선 벡터와 이동 방향 벡터가 이루는 각도가 둔각이면 올라가는 것
            /// Handy.Log("OnGround()");
            
            // 앞 부분 Ray와 뒤 부분 Ray의 경사각이 다른 경우
            if (rayB.normal.normalized != rayF.normal.normalized)
            {
                bool isTouchingSlopeFromB = rayB.normal.x == 0;
                /// Transform pos = isTouchingSlopeFromB ? groundCheckBack : groundCheckFront;
                RaycastHit2D ray = isTouchingSlopeFromB ? rayB : rayF;

                Vector2 from = FacingRight ? Vector2.right : Vector2.left;
                float rayAngle = Vector2.Angle(from, ray.normal);
                float rayAngleRad = Mathf.Deg2Rad * rayAngle;

                float sx = _movingSpeed * Mathf.Cos(rayAngleRad);
                float sy = _movingSpeed * Mathf.Sin(rayAngleRad);
                float vx = FacingRight ? sx : -sx;

                if (Jumping || Flying)
                {
                }
                // 예각이라면 내려갑니다.
                else if (rayAngle < 90)
                {
                    float vy = -sy;
                    _Velocity = new Vector2(vx, vy);
                }
                // 둔각이라면 올라갑니다.
                else if (rayAngle > 90)
                {
                    float vy = sy;
                    _Velocity = new Vector2(vx, vy);
                }
                // 90도라면
                else
                {
                }
            }
            else
            {
            }

            Landed = true;
        }
        else if (rayB || rayF)
        {
            // 가장 가까운 거리에 적중한 Ray를 탐색합니다.
            RaycastHit2D ray;
            if (rayB && !rayF)
            {
                ray = rayB;
            }
            else if (!rayB && rayF)
            {
                ray = rayF;
            }
            else
            {
                ray = rayB.distance < rayF.distance ? rayB : rayF;
            }

            /// Vector3 pos = transform.position;
            /// pos.y -= difY;
            
            // 지형과 Y 좌표의 차이가 작으면 추락을 중지합니다.
            float difY = ray.distance / transform.localScale.y;
            if (Mathf.Abs(difY) < _jumpDecSize)
            {
                // transform.position = pos;
                float vy = _Velocity.y > 0 ? _Velocity.y : 0;
                _Velocity = new Vector2(_Velocity.x, vy);
                Landed = true;
            }
            else
            {
                Landed = false;
            }
        }
        else if (Jumping || Falling || Flying)
        {
            Landed = false;
        }
        else
        {
            Landed = false;
        }
        return Landed;
    }

19 View Source File : AnimalMovement.cs
License : MIT License
Project Creator : Interactml

protected virtual void Falling()
        {
            // fall_Point = Chest_Pivot_Point;
            // if (!Fly)
            fall_Point = Main_Pivot_Point + (T_Forward * (Shift ? GroundSpeed + 1 : GroundSpeed) * FallRayDistance * ScaleFactor); //Calculate ahead the falling ray

            if (FrameCounter % FallRayInterval != 0) return;         //Skip to reduce aditional raycasting

            //Don't Calcultate Fall Ray if the animal on any of these states    
            if (AnimState == AnimTag.Sleep ||
                AnimState == AnimTag.Action ||
                AnimState == AnimTag.Swim ||
                AnimState == AnimTag.Idle ||
                swim == true ||
                underwater) return;


            float Multiplier = Pivot_Multiplier;

            if (AnimState == AnimTag.Jump || AnimState == AnimTag.Fall || AnimState == AnimTag.Fly)
            {
                Multiplier *= FallRayMultiplier;
            }

           

            //Set the Fall Ray a bit farther from the front feet.
            if (Physics.Raycast(fall_Point, -T_Up, out FallRayCast, Multiplier, GroundLayer))
            {
                if (debug)
                {
                    Debug.DrawRay(fall_Point, -T_Up * Multiplier, Color.magenta);
                    MalbersTools.DebugPlane(FallRayCast.point, 0.1f, Color.magenta, true);
                }

                float fallSlopeAngle = Vector3.Angle(FallRayCast.normal, Vector3.up);
                fallSlopeAngle *= Vector3.Dot(T_ForwardNoY, FallRayCast.normal) > 0 ? 1 : -1; //Calcualte the Fall Angle Positive or Negative

                if ((fallSlopeAngle > maxAngleSlope) || (!frontray && !backray))        //found something but there's no BACK/FrontRay
                {
                    fall = true;
                    return;
                }

                fall = false;

                CheckForLanding();

                if (AnimState == AnimTag.SwimJump) Swim = false;            //in case is jumping from the water to the ground ***Important
            }
            else
            {
                fall = true;
                FallRayCast.normal = UpVector;    //if there's no fall ray Reset the Fall Normal to the Horizontal Terrain
                if (debug)
                {
                    MalbersTools.DebugPlane(fall_Point + (-T_Up * Multiplier), 0.1f, Color.gray, true);
                    Debug.DrawRay(fall_Point, -T_Up * Multiplier, Color.gray);
                }
            }
        }

19 View Source File : AnimalAIControl.cs
License : MIT License
Project Creator : Interactml

private void FreeMovement()
        {
            if (IsWaiting) return;
            if (target ==null || targetPosition == NullVector) return; //If we have no were to go then Skip the code

            RemainingDistance = target ? Vector3.Distance(animal.transform.position, target.position) : 0;

            var Direction = (target.position - animal.transform.position);

            animal.Move(Direction);

            Debug.DrawRay(animal.transform.position, Direction.normalized, Color.white);

            if (RemainingDistance < StoppingDistance/* && !IsWaiting*/)   //We arrived to our destination
            {
                if (NextWayPoint != null && NextWayPoint.PointType != WayPointType.Air && animal.Fly) animal.SetFly(false); //If we arrive to our point and it was not an Air Point Disable Fly

                CheckNextTarget();
                // SetNextTarget();
            }
        }

19 View Source File : AnimalMovement.cs
License : MIT License
Project Creator : Interactml

protected void RayCasting()
        {
            if (AnimState != AnimTag.Jump
                && AnimState != AnimTag.JumpEnd
                && AnimState != AnimTag.Recover
                && AnimState != AnimTag.Fall)
            {
                if (FrameCounter % PivotsRayInterval != 0) return;         //Skip to reduce aditional raycasting
            }

            if (underwater) return;

            UpVector = -Physics.gravity;
            scaleFactor = _transform.localScale.y;                       //Keep Updating the Scale Every Frame
            _Height = height * scaleFactor;                              //multiply the Height by the scale

            backray = frontray = false;

            hit_Chest = NULLRayCast;                               //Clean the Raycasts every time 
            hit_Hip = NULLRayCast;                                 //Clean the Raycasts every time 

            hit_Chest.distance = hit_Hip.distance = _Height;       //Reset the Distances to the Heigth of the animal (IMPORTANT)

            if (Pivot_Hip != null) //Ray From the Hip to the ground
            {
                if (Physics.Raycast(Pivot_Hip.GetPivot, -T_Up, out hit_Hip, scaleFactor * Pivot_Hip.multiplier, GroundLayer))
                {
                    if (debug) Debug.DrawRay(hit_Hip.point, hit_Hip.normal * 0.2f, Color.blue);

                    float BackSlopeAngle = Vector3.Angle(hit_Hip.normal, Vector3.up);

                    if (BackSlopeAngle < maxAngleSlope)

                    {
                        backray = true;

                        if (Platform == null && AnimState != AnimTag.Jump)               //Platforming logic
                        {
                            Platform = hit_Hip.transform;
                            platform_Pos = Platform.position;
                            platform_formAngle = Platform.eulerAngles.y;
                        }
                        CheckForLanding();
                    }
                }
                else { Platform = null; }
            }

            //Ray From Chest to the ground ***Use the pivot for calculate the ray... but the origin position to calculate the distance
            if (Physics.Raycast(Main_Pivot_Point, -T_Up, out hit_Chest, Pivot_Multiplier, GroundLayer))
            {
                if (debug) Debug.DrawRay(hit_Chest.point, hit_Chest.normal * 0.2f, Color.red);

                float frontSlopeAngle = Vector3.Angle(hit_Chest.normal, Vector3.up);

                if (frontSlopeAngle < maxAngleSlope) frontray = true;

                CheckForLanding();
            }

            if (debug && frontray && backray)
            {
                Debug.DrawLine(hit_Hip.point, hit_Chest.point, Color.yellow);
            }

            if (!frontray && Stand) //Hack if is there's no ground beneath the animal and is on the Stand Sate;
            {
                fall = true;

                if (pivot_Hip && backray) fall = false;
            }

            FixDistance = hit_Hip.distance;
            if (!backray) FixDistance = hit_Chest.distance;         //if is landing on the front feets


            if (!Pivot_Hip) backray = frontray;    //In case there's no backray
            if (!Pivot_Chest) frontray = backray;    //In case there's no frontRay
        }

19 View Source File : AnimalMovement.cs
License : MIT License
Project Creator : Interactml

protected virtual bool IsFallingBackwards(float ammount)
        {
            if (FrameCounter % FallRayInterval != 0) return false;         //Skip to reduce aditional raycasting

            RaycastHit BackRay = new RaycastHit();
            var point = Pivot_Hip ? Pivot_Hip.transform.position : _transform.position + new Vector3(0, _Height, 0);
            var multiplier = Pivot_Hip ? Pivot_Hip.multiplier * FallRayMultiplier : FallRayMultiplier;

            Vector3 FallingVectorBack = point + T_Forward * -1 * ammount;

            if (debug) Debug.DrawRay(FallingVectorBack, -T_Up * multiplier * scaleFactor, Color.white);                 //Draw a White Ray

            if (Physics.Raycast(FallingVectorBack, -T_Up, out BackRay, scaleFactor * multiplier, GroundLayer))
            {
                if (BackRay.normal.y < 0.6)  // if the back ray if in Big Angle don't walk 
                {
                    return true;
                }
                return false;
            }
            else
            {
                if (!swim && movementAxis.z < 0) return true; //Check if the animal is moving backwards
            }
            return false;
        }

19 View Source File : JumpBehaviour.cs
License : MIT License
Project Creator : Interactml

void Can_Fall(float normalizedTime)
        {
            Debug.DrawRay(animal.Pivot_fall, -transform.up * animal.Pivot_Multiplier * fallRay, Color.red);

            if (MinJumpLand > 0)
            {
              
                if (Physics.Raycast(animal.Pivot_fall, -transform.up, out JumpRay, animal.Pivot_Multiplier * fallRay, animal.GroundLayer))
                {
                    float distance = Vector3.Distance(animal.Pivot_fall, JumpRay.point);
                    float Angle = Vector3.Angle(Vector3.up, JumpRay.normal);

                  if (animal.debug)  Debug.Log("Min Distance to complete the Jump: "+ distance);

                    if ((MinJumpLand * animal.ScaleFactor) < distance || Angle > animal.maxAngleSlope)
                    {
                        animal.SetIntID(111);
                        MalbersTools.DebugTriangle(JumpRay.point, 0.1f, Color.yellow);
                    }
                }
                else
                { animal.SetIntID(111); }
            }
            else if (Physics.Raycast(animal.Pivot_fall, -transform.up, out JumpRay, animal.Pivot_Multiplier * fallRay, animal.GroundLayer))
            {
                if ((jumpPoint - JumpRay.point.y) <= (stepHeight * animal.ScaleFactor)
                    && (Vector3.Angle(JumpRay.normal, Vector3.up) < animal.maxAngleSlope))      //If if finding a lower jump point;
                {
                    MalbersTools.DebugTriangle(JumpRay.point, 0.1f, Color.red);
                }
                else
                {
                    animal.SetIntID(111);           //Set INTID to 111 to activate the FALL transition
                    MalbersTools.DebugTriangle(JumpRay.point, 0.1f, Color.yellow);
                }
            }
            else
            {
                animal.SetIntID(111);                //Set INTID to 111 to activate the FALL transition
                MalbersTools.DebugPlane(animal.Pivot_fall - (transform.up * animal.Pivot_Multiplier * fallRay), 0.1f, Color.red);
            }
        }

19 View Source File : FallBehavior.cs
License : MIT License
Project Creator : Interactml

override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            //if (!animator.IsInTransition(layerIndex))
            //{
            //    rb.useGravity = true;
            //    animator.applyRootMotion = false;
            //    rb.constraints = RigidbodyConstraints.FreezeRotation;
            //}

            if (animal.debug)  Debug.DrawRay(animal.Main_Pivot_Point, -animal.transform.up * 50, Color.magenta);


            if (animal.CanDoubleJump && animal.Double_Jump == 0)
            {
                if (animal.Jump)
                {
                    animal.Double_Jump++;
                    animal.SetIntID(112);
                }
            }


            if (Physics.Raycast(animal.Main_Pivot_Point, -animal.transform.up, out FallRay, 50, GroundLayer))
            {
                if (MaxHeight < FallRay.distance)
                {
                    MaxHeight = FallRay.distance; //get the Highest Distance the first time you touch the ground
                }

                FallBlend = Mathf.Lerp(FallBlend, (FallRay.distance - LowerDistance) / (MaxHeight - LowerDistance), Time.deltaTime * 20); //Small blend in case there's a new ground found

                animator.SetFloat(Hash.IDFloat, FallBlend); //Blend between High and Low Fall

            }
            CheckforWater();
        }

19 View Source File : JumpBehaviour.cs
License : MIT License
Project Creator : Interactml

void Can_Jump_on_Cliff(float normalizedTime)
        {
          if (normalizedTime >= Cliff.minValue && normalizedTime <= Cliff.maxValue)
            {
                if (Physics.Raycast(animal.Main_Pivot_Point, -transform.up, out JumpRay, CliffRay * animal.ScaleFactor, animal.GroundLayer))
                {
                    if (Vector3.Angle(JumpRay.normal, Vector3.up) < animal.maxAngleSlope)       //Jump to a jumpable cliff not an inclined one
                    {
                        if (animal.debug)
                        {
                            Debug.DrawLine(animal.Main_Pivot_Point, JumpRay.point, Color.black);
                            MalbersTools.DebugTriangle(JumpRay.point, 0.1f, Color.black);
                        }
                        animal.SetIntID(110);
                    }
                }
                else
                {
                    if (animal.debug)
                    {
                        Debug.DrawRay(animal.Main_Pivot_Point, - transform.up * CliffRay * animal.ScaleFactor, Color.black);
                        MalbersTools.DebugPlane(animal.Main_Pivot_Point - ( transform.up * CliffRay * animal.ScaleFactor), 0.1f, Color.black);
                    }
                }
            }
        }

19 View Source File : DistanceGrabber.cs
License : MIT License
Project Creator : Tobbse

void Update()
        {

            Debug.DrawRay(transform.position, transform.forward, Color.red, 0.1f);
            
            DistanceGrabbable target;
            Collider targetColl;
            FindTarget(out target, out targetColl);

            if (target != m_target)
            {
                if (m_target != null)
                {
                    m_target.Targeted = m_otherHand.m_target == m_target;
                }
                if(m_target != null)
                    m_target.ClearColor();
                if(target != null)
                    target.SetColor(m_focusColor);
                m_target = target;
                m_targetCollider = targetColl;
                if (m_target != null)
                {
                    m_target.Targeted = true;
                }
            }
        }