Esempio n. 1
0
        private bool CheckIntersect()
        {
            var endPoint   = GetEndPoint();
            var startPoint = _player.Position + GetPlayerOffset();

            var direction = (endPoint - startPoint);

            direction.Normalize();
            var distance = Vector3.Distance(startPoint, endPoint);

            var collider = new RayCollider {
                Ray = new Ray(startPoint, direction)
            };

            return(_level.Objects.Any(o =>
            {
                if (!(o is Player))
                {
                    var rayCastResult = collider.Intersects(o.Collider);
                    if (rayCastResult.HasValue && Math.Abs(rayCastResult.Value) <= distance)
                    {
                        if (Math.Abs(rayCastResult.Value - distance) <= SPEED)
                        {
                            Status = ClawStatus.ClawHit;
                        }

                        return true;
                    }
                }
                return false;
            }));
        }
Esempio n. 2
0
 public void addCollider(RayCollider collider)
 {
     if (m_colliders == null)
     {
         m_colliders = new List <RayCollider>();
     }
     m_colliders.Add(collider);
 }
    SHR_Waypoint wp => (SHR_Waypoint)target;  //are we using the Inspector to look at a Waypoint?

    public void SnapToGround()
    {
        var hitResult = RayCollider.Raycast(wp.transform.position, Vector3.down, 100);

        if (hitResult.AnyGround)
        {
            wp.transform.position = hitResult.hit.point;
        }
    }
Esempio n. 4
0
 private void DrawLine(RayCollider line, bool intersect_line_circle, Vector2 normal, float fraction)
 {
     Gizmos.color = intersect_line_circle ? Color.green : Color.blue;
     Gizmos.DrawLine(line.p1, line.p2);
     if (intersect_line_circle)
     {
         Gizmos.color = Color.yellow;
         Vector2 pos_intersect = line.p1 + fraction * (line.p2 - line.p1);
         Gizmos.DrawLine(pos_intersect, pos_intersect + normal);
     }
 }
Esempio n. 5
0
    public void reUse(float x, float y, float dirX, float dirY, RayCollider origin, float intensity, float r = 1, float g = 1, float b = 1, float a = 1, int maxDepth = stdDepth)
    {
        m_position.Set(x, y);
        m_direction.Set(dirX, dirY);
        setColor(r, g, b, a);
        m_maxDepth  = maxDepth;
        m_origin    = origin;
        m_intensity = intensity;

        m_hasBounce = false;
    }
Esempio n. 6
0
 public RayHit(Ray ray, Vector2 point, Vector2Int pixel, Vector2 normal, RayCollider collider, Color color)
 {
     this.ray        = ray;
     this.point      = point;
     this.normal     = normal;
     this.collider   = collider;
     this.color      = color;
     this.nullHit    = false;
     this.pixel      = pixel;
     fromInsideShape = false;
 }
Esempio n. 7
0
 public void unRegister(RayCollider collider)
 {
     if (m_colliders == null)
     {
         return;
     }
     m_colliders.Remove(collider);
     collider.removeCallBackOnChange(onColliderChange);
     --m_colliderCount;
     //m_bih.removeCollider(collider);
 }
Esempio n. 8
0
 // Sets ray hit to 'null'
 // 'null' can be detected using the RayHit.nullHit
 public RayHit(Ray ray)
 {
     this.ray        = ray;
     this.point      = new Vector2(0, 0);
     this.normal     = new Vector2(0, 0);
     this.collider   = null;
     this.color      = new Color(0, 0, 0);
     this.nullHit    = true;
     this.pixel      = new Vector2Int(0, 0);
     fromInsideShape = false;
 }
Esempio n. 9
0
 public void register(RayCollider collider)
 {
     if (m_colliders == null)
     {
         m_colliders = new List <RayCollider>();
     }
     collider.callBackOnChange(onColliderChange);
     m_colliders.Add(collider);
     ++m_colliderCount;
     //m_bih.addCollider(collider);
 }
Esempio n. 10
0
        //private (Point point, BuildNode buildNode) GetSelectedGridPoint()
        //{
        //}

        public void Tick(TickContext context)
        {
            var mouse     = Mouse.GetState();
            var screenPos = new Vector2(
                mouse.X / (float)GraphicsDevice.Viewport.Width,
                1.0f - (mouse.Y / (float)GraphicsDevice.Viewport.Height)
                ) * 2 - new Vector2(1, 1);
            //Console.WriteLine($"screen {screenPos}");

            //Console.WriteLine(screenPos);
            //Console.WriteLine(worldDirectionVector);
            var ray = Camera.CreateRay(screenPos);
            var res = RayCollider.RayCast(ray, (byte)HitLayers.BuildTile);
            // Console.WriteLine($"Location: {res.location}");

            var buildNode = res.entity?.Get <BuildNode>();

            if (buildNode != null)
            {
                //Console.WriteLine($"{buildNode.GridLocation}");
            }
            this.Update(() => HoverNode = buildNode);

            if (PlacingSection != null)
            {
                if (KeyControls.HasBeenPressed(Keys.R))
                {
                    PlacingSection.Rotate(1);
                }
                if (MouseControls.RightClicked)
                {
                    CancelPlacing();
                }
                else if (buildNode != null && MouseControls.LeftClicked)
                {
                    var gridLocation = buildNode.GridLocation;
                    if (_shipTopology.SectionAt(gridLocation) == null &&
                        _shipTopology.LegalSectionCheck(PlacingSection, gridLocation))
                    {
                        this.Update(() =>
                        {
                            _shipTopology.SetSection(gridLocation, PlacingSection);
                            _productionLine.Remove(PlacingSection);
                            PlacingSection = null;
                            SoundEffects.Get("Hammer")?.Play();
                        });
                    }
                    else
                    {
                        SoundEffects.Get("Click")?.Play();
                    }
                }
            }
        }
Esempio n. 11
0
    private Ray(Vector2 position, Vector2 direction, RayCollider origin, float intensity, Color color, int maxDepth = stdDepth)
    {
        m_position  = position;
        m_direction = direction;
        m_color     = color;
        m_maxDepth  = maxDepth;
        m_origin    = origin;
        m_intensity = intensity;

        m_hasBounce  = false;
        m_bounce     = null;
        m_bounceInfo = new RayHit(this);
    }
Esempio n. 12
0
    public static Ray requestRay(Vector2 position, Vector2 direction, RayCollider origin, float intensity, Color color, int maxDepth = stdDepth)
    {
        Ray ray;

        if (m_recycledRays != null && m_recycledRays.Count != 0)
        {
            int last = m_recycledRays.Count - 1;
            ray = m_recycledRays[last];
            m_recycledRays.RemoveAt(last);
            ray.reUse(position.x, position.y, direction.x, direction.y, origin, intensity, color.r, color.g, color.b, color.a, maxDepth);
        }
        else
        {
            ray = new Ray(position, direction, origin, intensity, color, maxDepth);
        }

#if (UNITY_EDITOR)
        RayVisualizer.instance.register(ray);
#endif
        return(ray);
    }
Esempio n. 13
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < OBJ_COUNT; i++)
        {
            squares[i] = new SquareCollider()
            {
                position = new Vector2(Random.Range(0, 10), Random.Range(0, 10)), rotation = Random.Range(0, 359), width = new Vector2(Random.Range(0.1f, 2), Random.Range(0.1f, 2))
            };
            circles[i] = new CircleCollider()
            {
                position = new Vector2(Random.Range(0, 10), Random.Range(0, 10)), radius = Random.Range(0.1f, 2)
            };
            rays[i] = new RayCollider()
            {
                p1 = new Vector2(Random.Range(0, 10), Random.Range(0, 10)), p2 = new Vector2(Random.Range(0, 10), Random.Range(0, 10))
            };
        }

        TestSqureCircle();
        TestSqureSqure();
        TestCircleCircle();
        TestRaySquare();
        TestRayCircle();
    }
Esempio n. 14
0
 public void onColliderChange(RayCollider collider)
 {
     m_reTrace = true;
 }
Esempio n. 15
0
 public void removeCollider(RayCollider collider)
 {
     m_colliders.Remove(collider);
 }
Esempio n. 16
0
	// Use this for initialization
	void Start () {
        if (GetComponent<RayCollider>() != null)
            rc = GetComponent<RayCollider>();
        else
            Debug.Log("RayCollider is missing on" + gameObject.name);
	}
Esempio n. 17
0
        void Rule_Climbing()
        {
            #region Rule
            if (newRule)
            {
                velXZ = Vector3.zero;
                velY  = 0;
                anim.Set(Anim.ClimbWallStart, 1);

                if (col.wall.hit.normal != Vector3.zero && Mathf.Abs(col.wall.hit.normal.y) < 0.707f)
                {
                    pos = col.wall.hit.point + col.wall.hit.normal * 0.5f;
                }
                colClimb = col.wall;
            }

            if ((colClimb = RayCollider.Raycast(pos + colClimb.hit.normal, -colClimb.hit.normal, 3)).ClimbableWall && Mathf.Abs(colClimb.hit.normal.y) < 0.707f)
            {
                LookAt(pos - colClimb.hit.normal);
                pos = colClimb.hit.point + colClimb.hit.normal * 0.5f;
                if (lStick.magnitude > deadZone)
                {
                    pos += matRot.MultiplyVector(lStick_s) * 6 * dt;
                }
            }

            else if (apprVel.y > 2 && lStickAngle * Mathf.Sign(lStickAngle) < 30)
            {
                Jump(4, false);
            }

            col.wallEnabled = false;
            #endregion
            #region Animation
            float la = 0;
            if (lStick_s.magnitude > deadZone)
            {
                la = lStickAngle;
                anim.SetSpeed(lStick_s.magnitude * 35);
                if (la > -45 && la < 45)
                {
                    anim.Set(Anim.ClimbWallUpStart, 1);
                }
                else if (la >= 45 && la <= 135)
                {
                    anim.Set(Anim.ClimbWallRightStart, 1);
                }
                else if (la > 135 || la < -135)
                {
                    anim.Set(Anim.ClimbWallDownStart, 1);
                }
                else if (la >= -135 && la <= -45)
                {
                    anim.Set(Anim.ClimbWallLeftStart, 1);
                }
            }
            else
            {
                anim.SetSpeed(25);
                if (la > -45 && la < 45)
                {
                    anim.Set(Anim.ClimbWallUpEnd, 1);
                }
                else if (la > 45 && la < 135)
                {
                    anim.Set(Anim.ClimbWallRightEnd, 1);
                }
                else if (la > 135 || la < -135)
                {
                    anim.Set(Anim.ClimbWallDownEnd, 1);
                }
                else if (la > -135 && la < -45)
                {
                    anim.Set(Anim.ClimbWallLeftEnd, 1);
                }
            }
            #endregion
        }
Esempio n. 18
0
        void Rule_Air()
        {
            #region Rule
            col.groundDepth = 0;
            col.UpdateGroundCollision();

            if (newRule)
            {
                liftOffVel = velXZ.magnitude;
            }

            if (col.ground.AnyGround && velY <= 0)
            {
                velY = 0;
                SetRule("Ground");
                return;
            }
            else if (col.ground.Slide)
            {
                SetRule("Sliding");
                return;
            }
            else if (col.ground.Water && velY < 0 && !col.waterIsShallow)
            {
                SetRule("Swimming");
                return;
            }
            else if (!t_blockHang.active && col.ceiling.HangableCeiling)
            {
                SetRule("Hanging");
                return;
            }

            if (jumping)
            {
                gravity = -20;
                if (velY < jumpCutoff)
                {
                    jumping = false;
                }
            }
            else
            {
                gravity = -30;
            }


            // Ledgegrab
            var lh = Raycast(forward * 2 + upward * 3, -upward, 1);
            if (lh.AnyGround)
            {
                float       dist  = DistTo(lh);
                CollideInfo ledge = new CollideInfo();
                for (float d = dist; d > 0; d -= 0.05f)
                {
                    var lh2 = RayCollider.Raycast(pos + d * Vec2D(pos, lh.hit.point), -upward, 2);
                    if (!lh2.AnyGround)
                    {
                        ledge = lh2;
                        break;
                    }
                }
                if (ledge.AnyGround)
                {
                    this.ledge = ledge;
                    SetRule("Ledgegrab");
                    return;
                }
            }


            ApplyGravity();

            if (helic)
            {
                if (superHelicAscend)
                {
                    superHelicRev = Mathf.Lerp(superHelicRev, 42, dt * 45);
                }
                else
                {
                    superHelicRev = Mathf.Lerp(superHelicRev, 0, dt * 1);
                }

                SFX("Rayman2/Rayman/helic").asrc.pitch = 1 + superHelicRev / 300;
                anim.SetSpeed(30 + superHelicRev / 7);

                SetFriction(6.5f, hasSuperHelic ? 2.6f : 7.5f);
                velY    += dt * superHelicRev;
                velY     = Mathf.Clamp(velY, hasSuperHelic ? -25 : -5, 5);
                selfJump = false;
            }
            else
            {
                if (slideJump)
                {
                    SetFriction(0.1f, 0);
                }
                else
                {
                    SetFriction(5, 0);
                }
                moveSpeed = 10;
            }


            MoveOrStrafe(6, helic ? 5 : -1);
            AlignY(10);

            if (pos.y < startPos.y - 1100)
            {
                SetRule("Falling");
            }
            #endregion
            #region Animation
            if (helic)
            {
                anim.Set(Anim.HelicEnable, 1);
            }
            else if (liftOffVel < 5 || !selfJump)
            {
                if (velY > 5 + jumpLiftOffVelY)
                {
                    anim.Set(Anim.JumpIdleLoop, 0);
                }
                else
                {
                    if (newRule)
                    {
                        anim.Set(Anim.FallIdleLoop, 0);
                    }
                    else
                    {
                        anim.Set(Anim.FallIdleStart, 1);
                    }
                }
            }
            else
            {
                if (velY > 5 + jumpLiftOffVelY)
                {
                    anim.Set(Anim.JumpRunLoop, 0);
                }
                else
                {
                    if (newRule)
                    {
                        anim.Set(Anim.FallRunLoop, 0);
                    }
                    else
                    {
                        anim.Set(Anim.FallRunStart, 1);
                    }
                }
            }
            #endregion
        }
Esempio n. 19
0
 // Use this for initialization
 void Start () {
     target = transform.position;
     rc = GetComponent<RayCollider>();
 }
Esempio n. 20
0
        protected override void OnInputMainActor()
        {
            if (forceNav)
            {
                return;
            }

            if (GetKeyDown(KeyCode.R))
            {
                Despawn();
            }

            if (iStrafeDown || iStrafeHold)
            {
                strafing = true;
            }

            if (iStrafeUp)
            {
                strafing = false;
            }

            if (iShootUp)
            {
                justShot = false;
            }

            switch (rule)
            {
            case "Ground":
            case "Riding":
                if (iJumpDown)
                {
                    Jump(4, false, true);
                }
                if (iShootDown && !lStickPress)
                {
                    SetRule("Charging");
                }
                else if (iShootDown)
                {
                    RayShoot();
                }
                break;

            case "Climbing":
                if (iJumpDown)
                {
                    Jump(4, false, true);
                }
                break;

            case "Hanging":
                if (iShootDown)
                {
                    RayShoot();
                }
                if (iJumpDown)
                {
                    SetRule("Air");
                    t_blockHang.Start(0.35f);
                }
                break;

            case "Sliding":
                if (iJumpDown)
                {
                    Jump(4, false, true, true);
                }
                if (iShootDown)
                {
                    RayShoot();
                }
                break;

            case "Swimming":
                if (iJumpDown && col.atWaterSurface)
                {
                    Jump(4, false);
                }
                break;

            case "Swinging":
                if (iJumpDown)
                {
                    vel = apprVel;
                    Jump(Mathf.Clamp(3 + apprVel.y * 0.35f, 3, 20), false, true);
                }
                break;

            case "Mounted":
                if (iShootDown)
                {
                    if (carryPerso != null)
                    {
                        RayThrowCarriedForward();
                    }
                    else
                    {
                        RayShoot();
                    }
                }
                if (iJumpDown)
                {
                    if (carryPerso != null)
                    {
                        RayThrowCarriedUp();
                    }
                    else
                    {
                        Timers("MountHyst").Start(0.5f);
                        SetMount(null);
                        Jump(4, false, true);
                    }
                }
                break;

            case "Carrying":
                if (iShootDown)
                {
                    RayThrowCarriedForward();
                }
                else if (iJumpDown)
                {
                    RayThrowCarriedUp();
                }
                break;

            case "Air":
                if (jumping && iJumpUp)
                {
                    jumping = false;
                }

                if (iJumpDown && !(helic && hasSuperHelic) && !slideJump)
                {
                    ToggleHelic();
                }

                superHelicAscend = hasSuperHelic && helic && iJumpHold;

                if (iShootDown)
                {
                    RayShoot();
                }

                // Moonjump
                if (GetKeyDown(KeyCode.JoystickButton1) || GetKeyDown(KeyCode.S))
                {
                    Jump(4, false);
                }

                break;
            }


            // Debug/Cheat stuff
            if (GetKeyDown(KeyCode.H))
            {
                hasSuperHelic = !hasSuperHelic;
            }

            if (GetKeyDown(KeyCode.T))
            {
                var c = RayCollider.RaycastMouse();
                if (c.Any)
                {
                    pos = c.hit.point;
                }
            }
        }
Esempio n. 21
0
 private Ray(Vector2 position, Vector2 direction, RayCollider origin, float intensity, int maxDepth = stdDepth) :
     this(position, direction, origin, intensity, new Color(1, 1, 1), maxDepth)
 {
 }
Esempio n. 22
0
 public static Ray requestRay(Vector2 position, Vector2 direction, RayCollider origin, float intensity, int maxDepth = stdDepth)
 {
     return(requestRay(position, direction, origin, intensity, new Color(1, 1, 1), maxDepth));
 }