示例#1
0
 /// <summary>
 /// A simple method to find the ground
 /// </summary>
 /// <param name="grounded"></param>
 /// <returns></returns>
 public bool GetGround(bool grounded)
 {
     if (raycast.isSphereCast)
     {
         Vector3 temp1, temp2;
         return(GetGround(out temp1, out temp2, grounded));
     }
     else
     {
         SetDistance(grounded);
         return(raycast.Cast());
     }
 }
示例#2
0
        private void Update()
        {
            raycast.direction         = direction;
            raycast.distance          = distance;
            raycast.sphereCastRadius  = radius;
            raycast.correctSphereCast = correctSphereCast;

            detector.detectionDistance = distance;
            detector.hoverDistance     = distance;

            Debug.DrawRay(raycast.origin, raycast.direction.normalized * raycast.distance);

            RaycastHit hit;

            if (raycast.Cast(out hit))
            {
                Debug.DrawRay(hit.point, hit.normal, Color.red);
            }

            Vector3 point, normal;

            if (detector.GetGround(out point, out normal, false))
            {
                Debug.DrawRay(point, normal, Color.green);
            }
        }
示例#3
0
        public override void Update(GameTime gameTime)
        {
            if (GameManager.Instance.MovementEnabled)
            {
                Vector2 camVector = InputHandler.Instance.GetCameraVector();
                tempYaw   = -CAM_YAW_SENSITIVITY * (float)gameTime.ElapsedGameTime.TotalMilliseconds * (camVector.X);
                tempPitch = CAM_PITCH_SENSITIVITY * (float)gameTime.ElapsedGameTime.TotalMilliseconds * (camVector.Y);

                tempPos = cam.Position;
                tempPos = tempPos / Math.Max(tempPos.Length(), 0.000001f);
                tempPos = distance * tempPos;
                tempPos = Vector3.Transform(tempPos,
                                            Matrix.CreateFromAxisAngle(cam.Right, tempPitch));

                Vector3 dir   = Vector3.Normalize(cam.Target - tempPos);
                float   angle = (float)Math.Atan2((double)dir.Y, Math.Sqrt((double)(dir.X * dir.X + dir.Z * dir.Z)));

                if (angle > -1.2f && angle < 0.4f)
                {
                    cam.Position = tempPos;
                }

                cam.Position = Vector3.Transform(cam.Position,
                                                 Matrix.CreateFromAxisAngle(cam.Up, tempYaw));

                if (InputHandler.Instance.NoClipVector() == Vector2.Zero)
                {
                    Vector3 tgt = Vector3.Normalize((cam.Position - cam.Target));

                    Raycast ray = new Raycast(cam.Target + cam.Translation + tgt,
                                              tgt,
                                              1.5f, 0.01f);
                    if (ray.Cast())
                    {
                        if (ray.ColliderHit.MyObject.UniqueID != this.MyObject.UniqueID)
                        {
                            cam.Position = ray.PositionHit - cam.Translation;
                        }
                    }
                }

                cam.Translation = new Vector3(target.MyTransform.Position.X, target.MyTransform.Position.Y, -target.MyTransform.Position.Z);
            }
        }