Example #1
0
 public void UpdateControl(FlightControl control)
 {
     control.Thrust           = MoveInputVector.z;
     control.Pitch            = LookInputVector.y;
     control.Yaw              = LookInputVector.x;
     control.StrafeHorizontal = MoveInputVector.x;
     control.StrafeVertical   = MoveInputVector.y;
 }
        public static void TurnTowardsPoint(this FlightControl control, TransformComponent nodeTr, Vector3 gotoPos)
        {
            Vector3 localGotoPos = nodeTr.InverseTransformVector(gotoPos - nodeTr.position).normalized;

            control.Pitch   = Mathf.Clamp(-localGotoPos.y * control.Config.PitchSensitivity, -1f, 1f);
            control.Yaw     = Mathf.Clamp(localGotoPos.x * control.Config.YawSensitivity, -1f, 1f);
            control.GotoPos = gotoPos;
            //_pitch = _turnPitchPID.Seek(-localGotoPos.y, _pitch, Time.deltaTime);
            //_yaw = _turnYawPID.Seek(localGotoPos.x, _yaw, Time.deltaTime);
        }
Example #3
0
        public void UpdateControl(FlightControl control)
        {
            control.GotoPos = GetMousePosition();
            if (!string.IsNullOrEmpty(Boost) && Input.Handler.GetButtonDown(Boost))
            {
                control.Boost = 1;
            }
            else
            {
                control.Boost = 0;
            }
            if (!string.IsNullOrEmpty(ThrustAxis))
            {
                control.Thrust = Input.Handler.GetAxis(ThrustAxis);
            }
            if (!string.IsNullOrEmpty(StrafeHorizontalAxis))
            {
                control.StrafeHorizontal = Input.Handler.GetAxis(StrafeHorizontalAxis);
            }
            if (!string.IsNullOrEmpty(StrafeVerticalAxis))
            {
                control.StrafeVertical = Input.Handler.GetAxis(StrafeVerticalAxis);
            }
            if (control.Config.UseMouse)
            {
                if (control.Config.UseDirectControl)
                {
                    var     mousePosition = UnityEngine.Input.mousePosition;
                    Vector3 mousePos      = new Vector3(mousePosition.x / Screen.width, mousePosition.y / Screen.height, 0) - new Vector3(0.5f, 0.5f, 0f);
                    mousePos = mousePos * 2; // Go from -1 to 1 left to right of screen

                    // Adjust the mouse distance taking into account the dead radius
                    float mouseDist = Vector3.Magnitude(mousePos);
                    mouseDist = Mathf.Max(mouseDist - control.Config.MouseDeadRadius, 0);
                    mousePos  = mousePos.normalized * mouseDist;

                    control.Pitch = Mathf.Clamp((control.Config.MouseVerticalInverted? 1 : -1) * mousePos.y * control.Config.MousePitchSensitivity, -1f, 1f);

                    if (control.Config.LinkYawAndRoll)
                    {
                        control.Roll = Mathf.Clamp(-mousePos.x * control.Config.MouseRollSensitivity, -1f, 1f);
                        control.Yaw  = Mathf.Clamp(-control.Roll * control.Config.YawRollRatio, -1f, 1f);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(RollAxis))
                        {
                            control.Roll = Input.Handler.GetAxis(RollAxis);
                        }
                        control.Yaw = Mathf.Clamp(mousePos.x * control.Config.MouseYawSensitivity, -1f, 1f);
                    }
                }
                else
                {
                    control.TurnTowardsPoint(control.GetEntity().GetTemplate <CollidableTemplate>().Tr, control.GotoPos);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(PitchAxis))
                {
                    control.Pitch = Input.Handler.GetAxis(PitchAxis);
                }
                if (!string.IsNullOrEmpty(YawAxis))
                {
                    control.Yaw = Input.Handler.GetAxis(YawAxis);
                }
                if (!string.IsNullOrEmpty(RollAxis))
                {
                    control.Roll = Input.Handler.GetAxis(RollAxis);
                }
            }
        }