Exemplo n.º 1
0
        public void UpdateWallCollision()
        {
            if (!wallEnabled)
            {
                return;
            }
            wallPush = new Vector3();
            wall     = new CollideInfo();
            var        most     = new Vector3();
            RaycastHit shortest = new RaycastHit {
                distance = radius
            };

            for (float h = bottom; h <= top; h += 0.25f)
            {
                for (float a = 0; a < Mathf.PI * 2; a += Mathf.PI * 2 / 16)
                {
                    var col = Raycast(pos + h * Vector3.up, new Vector3(Mathf.Sin(a), 0, Mathf.Cos(a)), radius);
                    if (col.AnyWall && col.hit.distance < shortest.distance)
                    {
                        most     = col.hit.normal * (-col.hit.distance + radius);
                        shortest = col.hit;
                        wall     = col;
                    }
                }
            }
            wallPush = new Vector3(most.x, 0, most.z);

            ceilPush = new Vector3();
            ceiling  = RaycastCeiling();
            if (ceiling.AnyWall)
            {
                ceilPush = ceiling.hit.normal * (-ceiling.hit.distance + ceilingHeight);
            }
        }
Exemplo n.º 2
0
        public void UpdateGroundCollision()
        {
            var p = pos;

            if (groundEnabled)
            {
                var groundHold = RaycastGround();
                if (groundHold.hit.normal.y > wallAngle)
                {
                    ground = groundHold;
                }
                else
                {
                    ground = new CollideInfo();
                }

                platformPerso = ground.hit.collider?.GetComponentInParent <PersoController>();
                groundFar     = Raycast(p + Vector3.up * (1 - groundLevel), Vector3.down, 1 + 10);
            }
            else
            {
                ground    = new CollideInfo();
                groundFar = new CollideInfo();
            }
        }
Exemplo n.º 3
0
 public void ClearAll()
 {
     ground    = new CollideInfo();
     groundFar = new CollideInfo();
     wall      = new CollideInfo();
     ceiling   = new CollideInfo();
     water     = new CollideInfo();
 }