public void Update(FrameTime frameTime)
        {
            if (!IsEnabled)
            {
                return;
            }
            var camera           = globalObjectService.MainCamera;
            var projectedForward = new Plane(ca.Vector3.UnitY, ca.Vector3.Zero).Project(camera.transform.forward.ToClarity());

            if (projectedForward.LengthSquared() < MathHelper.Eps8)
            {
                return;
            }
            var dpadOffset              = SteamVR_Actions.default_DpadOrientation.GetAxis(SteamVR_Input_Sources.RightHand);
            var forward                 = projectedForward.Normalize();
            var right                   = ca.Vector3.Cross(forward, ca.Vector3.UnitY);
            var controllerMovement      = forward * dpadOffset.y + right * dpadOffset.x;
            var cameraHeightOffset      = 1f;
            var startingPoint           = globalObjectService.VrPlayerCarrier.transform.position.ToClarity() + cameraHeightOffset * ca.Vector3.UnitY;
            var offset                  = controllerMovement * Speed * frameTime.DeltaSeconds;
            var unrestrictedNewPosition = startingPoint + offset;
            var restrictedNewPosition   = collisionMesh.RestrictMovement(0.5f, startingPoint, offset);

            restrictedNewPosition.Y = unrestrictedNewPosition.Y - cameraHeightOffset;
            globalObjectService.VrPlayerCarrier.transform.position = restrictedNewPosition.ToUnity();
        }
Example #2
0
        public bool SweepCollision(Vector3 currentPosition, Vector3 proposedDirection, float distance)
        {
            proposedDirection.y = 0;
            proposedDirection.Normalize();
            var offset            = (proposedDirection * distance).ToClarity();
            var currentPosClarity = currentPosition.ToClarity() + 1 * ca.Vector3.UnitY;
            var expectedTarget    = currentPosClarity + 1 * ca.Vector3.UnitY + offset;
            var target            = collisionMesh.RestrictMovement(radius, currentPosClarity, offset);

            return(target.Xz != expectedTarget.Xz);
        }
        public void Update(FrameTime frameTime)
        {
            var frame         = GetGlobalFrame();
            var eye           = frame.Eye;
            var planarForward = new Vector3(frame.Forward.X, 0, frame.Forward.Z).Normalize();
            var planarRight   = Vector3.Cross(planarForward, Vector3.UnitY);

            var accel = Vector3.Zero;

            if (inputService.CurrentKeyboardState.IsKeyPressed(Key.W))
            {
                accel += planarForward * Accel;
            }
            if (inputService.CurrentKeyboardState.IsKeyPressed(Key.S))
            {
                accel -= planarForward * Accel;
            }
            if (inputService.CurrentKeyboardState.IsKeyPressed(Key.D))
            {
                accel += planarRight * Accel;
            }
            if (inputService.CurrentKeyboardState.IsKeyPressed(Key.A))
            {
                accel -= planarRight * Accel;
            }
            if (accel.LengthSquared() >= MathHelper.Eps8)
            {
                accel = accel.Normalize() * Accel;
            }

            if (accel.X == 0)
            {
                horrVelocity.X *= 0.7f;
            }
            if (accel.Z == 0)
            {
                horrVelocity.Z *= 0.7f;
            }

            horrVelocity += new Vector3(accel.X, 0, accel.Z) * frameTime.DeltaSeconds;
            vertVelocity += accel.Y;

            if (horrVelocity.LengthSquared() > MaxVelocitySq)
            {
                horrVelocity = horrVelocity.Normalize() * MaxVelocity;
            }

            // todo: check that the horizontal speed is limited by MaxVelocity

            var gravity = zoning.GetZonePropertiesAt(eye).Gravity;

            if (gravity != 0)
            {
                if (vertVelocity == 0 && inputService.CurrentKeyboardState.IsKeyPressed(Key.Space))
                {
                    vertVelocity = JumpVelocity;
                }
                else
                {
                    vertVelocity += gravity * frameTime.DeltaSeconds;
                }
            }
            else
            {
                if (inputService.CurrentKeyboardState.IsKeyPressed(Key.Space))
                {
                    vertVelocity += Accel;
                }
                else if (inputService.CurrentKeyboardState.IsKeyPressed(Key.C))
                {
                    vertVelocity -= Accel;
                }
                else
                {
                    vertVelocity *= 0.7f;
                }

                if (vertVelocity > MaxVelocity)
                {
                    vertVelocity = MaxVelocity;
                }
                if (vertVelocity < -MaxVelocity)
                {
                    vertVelocity = -MaxVelocity;
                }
            }

            var velocity = new Vector3(horrVelocity.X, vertVelocity, horrVelocity.Z);
            var newPos   = collisionMesh.RestrictMovement(0.8f, eye, velocity * frameTime.DeltaSeconds);

            velocity     = (newPos - eye) / frameTime.DeltaSeconds;
            vertVelocity = velocity.Y;
            horrVelocity = new Vector3(velocity.X, 0, velocity.Z);
            props.Eye    = newPos;
        }