Beispiel #1
0
    void Awake()
    {
        animator    = transform.Find("PauseGraphic").GetComponent <Animator>();
        _controller = GetComponent <CharacterController2D>();

        // listen to some events for illustration purposes
        _controller.onControllerCollidedEvent += onControllerCollider;
        _controller.onTriggerEnterEvent       += onTriggerEnterEvent;
        _controller.onTriggerExitEvent        += onTriggerExitEvent;

        // Water collider
        waterCollider.onEnterWater = waterObject => {
            animator.SetTrigger("StartPaddleing");
            _velocity       = new Vector3(0, _velocity.y / 2, 0);
            enteringWater   = true;
            startSurfaceing = false;
            topOfWater      = waterObject.GetComponent <BoxCollider2D>().bounds.max.y;
            movementMode    = MovementModes.SwimmingSurface;
            Splash();
        };

        waterCollider.onExitWater = waterObject => {
            //Splash();
            //if(!enteringWater)
            //	movementMode = MovementModes.Normal;
        };
    }
Beispiel #2
0
 void Start()
 {
     // SMALL MOVEMENT DELAY ON LEVEL START
     movementMode = MovementModes.NoPlayerInteraction;
     //MugHeadStudios.MHS.WaitRun(0.1f, () => {
     movementMode = MovementModes.Normal;
     //});
 }
Beispiel #3
0
    private void Start()
    {
        movementState    = MovementModes.walk;
        currentBoostTime = maxBoostTime;

        characterController = GetComponent <CharacterController>();
        viewCam             = Camera.main;
        guiCam = GameObject.Find("GUICamera").GetComponent <Camera>();
    }
 void SwitchModes(MovementModes newmode)
 {
     try {
         modeManager.switchModes (newmode);
     } catch (Exception e) {
         Debug.LogError (string.Format("({0} -- Free Flight Component): Script Failed Switching Modes: [{1}] {2} \n{3}",
                                       gameObject.name, e.GetType().ToString(), e.Message, e.StackTrace.ToString()));
         enabled = false;
     }
 }
 /// <summary>
 /// Applies sprint changes to character movement.
 /// </summary>
 /// <param name="sprinting">Is sprint button pressed?</param>
 private void ApplySprint(bool sprinting)
 {
     if (sprinting == true)
     {
         this.currentMoveMode = MovementModes.Sprint;
     }
     else
     {
         this.currentMoveMode = MovementModes.Normal;
     }
 }
 /// <summary>
 /// Applies crouch changes to character movement.
 /// </summary>
 /// <param name="crouching">Is crouch button pressed?</param>
 private void ApplyCrouch(bool crouching)
 {
     if (crouching == true)
     {
         this.currentMoveMode = MovementModes.Crouch;
     }
     else
     {
         this.currentMoveMode = MovementModes.Normal;
     }
 }
 void SwitchMovementMode()
 {
     if (currentMovementMode == MovementModes.ROTATING)
     {
         currentMovementMode = MovementModes.STRAFING;
     }
     else if (currentMovementMode == MovementModes.STRAFING)
     {
         currentMovementMode = MovementModes.ROTATING;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Sends specified coordinates and movement mode to GCode instance.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="movementMode"></param>
        private void SendToGCode(int x, int y, int z, MovementModes movementMode)
        {
            switch (movementMode)
            {
            case MovementModes.Print:
                gcode.AddCommand(x, y, z, MovementModes.Print);
                break;

            case MovementModes.Move:
                gcode.AddCommand(x, y, z, MovementModes.Move);
                break;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Adds a GCode command to the list using the given X, Y, and Z coordinates, as well as a speed based on the movement mode.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="movementMode"></param>
        public void AddCommand(int x, int y, int z, MovementModes movementMode)
        {
            switch (movementMode)
            {
            case MovementModes.Print:
                GCodeCommands.Add("G1" + " X" + x.ToString() + " Y" + y.ToString() + " Z" + z.ToString() + " F" + Properties.Settings.Default.PrintSpeed);
                break;

            case MovementModes.Move:
                GCodeCommands.Add("G1" + " X" + x.ToString() + " Y" + y.ToString() + " Z" + z.ToString() + " F" + Properties.Settings.Default.MoveSpeed);
                break;

            default:
                break;
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        leftControl  = KeyCode.LeftControl;
        rightControl = KeyCode.RightControl;

        moveSpeed           = 5f;
        turnSpeed           = 100f;
        movementSwitchTimer = 0f;

        currentMovementMode = MovementModes.STRAFING;

        shootingCD = 0f;

        currentHealth = maxHealth;

        score    = 0;
        spawnPos = transform.position;
        gameOverBG.gameObject.SetActive(false);
    }
Beispiel #11
0
    void ChangeMovementMode(MovementModes newMode)
    {
        switch (_movementMode)
        {
        case MovementModes.AttachedToHand:
            _movementTargetTransform = _anchorTransform;
            break;

        case MovementModes.FloatingToHand:
            break;

        case MovementModes.FreeFloating:
            break;

        case MovementModes.Thrown:
            _movementSpeed         = _rigidbody.velocity.magnitude;
            _movementDirection     = _rigidbody.velocity.normalized;
            _rigidbody.isKinematic = true;
            break;
        }

        switch (newMode)
        {
        case MovementModes.AttachedToHand:
            break;

        case MovementModes.FloatingToHand:
            break;

        case MovementModes.FreeFloating:
            _movementTargetTransform = _anchorTransform;
            break;

        case MovementModes.Thrown:
            _rigidbody.isKinematic = false;
            _rigidbody.velocity    = _movementDirection.normalized * _movementSpeed;
            _thrownTimer           = _thrownStateDuration;
            break;
        }

        _movementMode = newMode;
    }
Beispiel #12
0
    public void Movement(Vector3 movePlayer, bool dash)
    {
        if (dash)
        {
            movementState    = MovementModes.boost;
            currentBoostTime = 0f;
            if (currentBoostTime < maxBoostTime)
            {
                characterController.Move(transform.TransformDirection(new Vector3(0f, 0f, boostSpeed) * Time.deltaTime));
                currentBoostTime += dashStopTime;
            }
        }
        else
        {
            movementState = MovementModes.walk;
        }

        if (movementState == MovementModes.walk)
        {
            characterController.Move(transform.TransformDirection(movePlayer.x, 0, -movePlayer.y) * walkSpeed * Time.deltaTime);
            viewCam.GetComponent <Camerabob>().Headbobbing(movePlayer.magnitude);
        }
    }
Beispiel #13
0
 public void SetMovementMode(MovementModes mode)
 {
    Tracer.WriteHigh(TraceGroup.TBUS, "", "requested movement mode={0}", mode);
    this.movementMode = mode;
 }
Beispiel #14
0
      private void InitializeValues()
      {
         this.busReady = false;
         this.busStatus = null;
         this.busReceiveQueue.Clear();
         this.deviceResetQueue.Clear();

         this.robotBody.NodeId = (byte)ParameterAccessor.Instance.RobotBus.RobotBodyBusId;
         this.robotTopFrontWheel.NodeId = (byte)ParameterAccessor.Instance.RobotBus.RobotTopFrontWheelBusId;
         this.robotTopRearWheel.NodeId = (byte)ParameterAccessor.Instance.RobotBus.RobotTopRearWheelBusId;
         this.robotBottomFrontWheel.NodeId = (byte)ParameterAccessor.Instance.RobotBus.RobotBottomFrontWheelBusId;
         this.robotBottomRearWheel.NodeId = (byte)ParameterAccessor.Instance.RobotBus.RobotBottomRearWheelBusId;

         this.TraceMask = ParameterAccessor.Instance.RobotBus.ControllerTraceMask;
         this.robotBody.TraceMask = ParameterAccessor.Instance.RobotBus.RobotBodyTraceMask;
         this.robotTopFrontWheel.TraceMask = ParameterAccessor.Instance.RobotBus.RobotTopFrontWheelTraceMask;
         this.robotTopRearWheel.TraceMask = ParameterAccessor.Instance.RobotBus.RobotTopRearWheelTraceMask;
         this.robotBottomFrontWheel.TraceMask = ParameterAccessor.Instance.RobotBus.RobotBottomFrontWheelTraceMask;
         this.robotBottomRearWheel.TraceMask = ParameterAccessor.Instance.RobotBus.RobotBottomRearWheelTraceMask;

         this.InitializeRobotBody();

         this.movementMode = MovementModes.off;
         this.movementForwardMode = MovementForwardModes.normalAxial;
         this.movementWheelModeChangeRequest = MovementWheelModes.neither;
         this.movementWheelModeActual = MovementWheelModes.neither;
         this.movementTopFrontWheelStatus.Initialize();
         this.movementTopRearWheelStatus.Initialize();
         this.movementBottomFrontWheelStatus.Initialize();
         this.movementBottomRearWheelStatus.Initialize();

         this.drillFrontRotationSetPoint = 0;
         this.drillRearRotationSetPoint = 0;
         this.drillFrontIndexSetPoint = 0;
         this.drillRearIndexSetPoint = 0;
         this.drillFrontLaserSetPoint = false;
         this.drillRearLaserSetPoint = false;

         this.cameraA = CameraLocations.robotFrontUpperBack;
         this.cameraB = CameraLocations.robotLowerBack;
         this.videoASetPoint = 0;
         this.videoBSetPoint = 0;

         for (int i = 0; i < this.cameraLightLevelSetPoints.Length; i++)
         {
            this.cameraLightLevelSetPoints[i] = 0;
         }
      }
 public void switchModes(MovementModes newmode)
 {
     activeMode = newmode;
 }
Beispiel #16
0
      private void ProcessStarting()
      {
         string versionString = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
         this.VersionLabel.Text = versionString;

         ParameterAccessor.Instance.Read(Application.ExecutablePath);
         this.traceListener.SetDestination(ParameterAccessor.Instance.Trace.Address, ParameterAccessor.Instance.Trace.Port);
         Tracer.WriteHigh(TraceGroup.GUI, null, "starting");

         if (RobotApplications.repair == ParameterAccessor.Instance.RobotApplication)
         {
            this.TitleLabel.Text = "  CIRRIS XR";

            this.FrontSealantReserviorPanel.Visible = true;
            this.RearSealantReserviorPanel.Visible = true;

            this.DrillMainPanel.Visible = true;

            this.InspectionPanel.Top = this.DrillMainPanel.Top;
            this.InspectionPanel.Left = this.DrillMainPanel.Left;
            this.InspectionPanel.Visible = false;

            ParameterAccessor.Instance.FrontDrill.ExtendedDistance.OperationalValue = 0;
            ParameterAccessor.Instance.FrontDrill.RotationSpeed.OperationalValue = 0;
            ParameterAccessor.Instance.RearDrill.ExtendedDistance.OperationalValue = 0;
            ParameterAccessor.Instance.RearDrill.RotationSpeed.OperationalValue = 0;

            this.RobotCamera6Button.Visible = true;
            this.RobotCamera11Button.Visible = true;

            this.RobotCamera2Button.Text = "RFF DRILL";
            this.RobotCamera6Button.Text = "FFF DRILL";
            this.RobotCamera10Button.Text = "LOWER FORWARD";
            this.RobotCamera9Button.Text = "RRF DRILL";
            this.RobotCamera11Button.Text = "FRF DRILL";
            this.RobotCamera12Button.Text = "LOWER BACK";

            this.RobotCamera2Button.Camera = CameraLocations.robotRffDrill;
            this.RobotCamera6Button.Camera = CameraLocations.robotFffDrill;
            this.RobotCamera10Button.Camera = CameraLocations.robotLowerForward;
            this.RobotCamera9Button.Camera = CameraLocations.robotRrfDrill;
            this.RobotCamera11Button.Camera = CameraLocations.robotFrfDrill;
            this.RobotCamera12Button.Camera = CameraLocations.robotLowerBack;
         }

         if (RobotApplications.inspect == ParameterAccessor.Instance.RobotApplication)
         {
            this.TitleLabel.Text = "  CIRRIS XI";

            this.FrontSealantReserviorPanel.Visible = false;
            this.RearSealantReserviorPanel.Visible = false;

            this.DrillMainPanel.Visible = false;
            this.DrillManualPanel.Visible = false;
            this.SealantMainPanel.Visible = false;
            this.SealantManualPanel.Visible = false;

            this.BodyDrillButton.Text = "";
            this.BodyDrillButton.Enabled = false;

            this.InspectionPanel.Top = this.DrillMainPanel.Top;
            this.InspectionPanel.Left = this.DrillMainPanel.Left;
            this.InspectionPanel.Visible = true;

            this.RobotCamera6Button.Visible = false;
            this.RobotCamera11Button.Visible = false;

            this.RobotCamera2Button.Text = "LOWER BACK";
            this.RobotCamera10Button.Text = "LOWER FORWARD";
            this.RobotCamera9Button.Text = "SENSOR ARM";
            this.RobotCamera12Button.Text = "SENSOR BAY";

            this.RobotCamera2Button.Camera = CameraLocations.robotLowerBack;
            this.RobotCamera10Button.Camera = CameraLocations.robotLowerForward;
            this.RobotCamera9Button.Camera = CameraLocations.robotSensorArm;
            this.RobotCamera12Button.Camera = CameraLocations.robotSensorBay;
         }

         this.indicatorFlasher = false;

         this.feederFastSelected = true;
         this.feederPreviousRequest = 0;
         this.feederNonManualMode = FeederModes.off;
         this.FeederSpeedToggleButton.OptionASelected = this.feederFastSelected;
         this.FeederManualPanel.Visible = false;
         this.FeederManulDisplayButton.Text = "SHOW MANUAL";
         this.FeederSpeedToggleButton.Visible = true;
         this.FeederSpeedValueButton.ValueText = this.GetValueText(ParameterAccessor.Instance.FeederManualSpeed);
         this.UpdateFeederControls();

         this.ReelCalibrateToButton.ValueText = this.GetValueText(ParameterAccessor.Instance.ReelCalibrationDistance);
         this.ReelManualCalibrateToButton.ValueText = this.GetValueText(ParameterAccessor.Instance.ReelCalibrationDistance);
         this.ReelCalibrateToButton.Enabled = false;
         this.ReelShowManualButton.Enabled = true;
         this.ReelManualDirectionToggleButton.OptionASelected = true;
         this.ReelManualDirectionToggleButton.Enabled = true;
         this.ReelSetupButton.Enabled = true;
         this.ReelManualSetupButton.Enabled = true;
         this.ReelManualHideButton.Enabled = true;
         this.UpdateReelControls();

         this.ReelManualPanel.Visible = false;
         
         if (MovementForwardControls.current == ParameterAccessor.Instance.ReelMotionMode)
         {
            this.ReelManualValueTextPanel.ValueText = this.GetValueText(ParameterAccessor.Instance.ReelManualCurrent);
            this.ReelManualDirectionToggleButton.Text = "TORQUE DIRECTION";
            this.ReelValuePromptLabel.Text = "SET CURRENT";
         }
         else
         {
            this.ReelManualValueTextPanel.ValueText = this.GetValueText(ParameterAccessor.Instance.ReelManualSpeed);
            this.ReelManualDirectionToggleButton.Text = "SPEED DIRECTION";
            this.ReelValuePromptLabel.Text = "SET SPEED";
         }

         this.movementFastSelected = true;
         this.movementNonManualMode = MovementModes.off;
         this.movementNonManualForwardMode = MovementForwardModes.normalAxial;
         this.MotorManualJogDistanceValueButton.ValueText = this.GetValueText(ParameterAccessor.Instance.MovementMotorManualJogDistance);
         this.MotorManualMoveSpeedValueButton.ValueText = this.GetValueText(ParameterAccessor.Instance.MovementMotorManualMoveSpeed);
         this.MovementSpeedToggleButton.OptionASelected = this.movementFastSelected;
         this.MovementManulPanel.Visible = false;
         this.MovementManaulDisplayButton.Text = "SHOW MANUAL";
         this.MovementSpeedToggleButton.Visible = true;
         this.UpdateMovementControls();

         #region Drill/Sealant Controls

         if (RobotApplications.repair == ParameterAccessor.Instance.RobotApplication)
         {
            this.toolLocation = (false != ParameterAccessor.Instance.FrontToolSelected) ? ToolLocations.front : ToolLocations.rear;
            this.SetDrillSelection(this.toolLocation);
            this.DrillManulDisplayButton.Text = "SHOW MANUAL";
            this.DrillMainPanel.Visible = true;
            this.DrillManualPanel.Visible = false;
            this.drillManualVisible = false;
            this.drillManualActivated = false;

            NicBotComm.Instance.SetPumpSpeed(this.toolLocation, 0);
            this.SealantManulDisplayButton.Text = "SHOW MANUAL";
            this.SealantMainPanel.Visible = false;
            this.SealantManualPanel.Visible = false;
            this.pumpManualVisible = false;
            this.pumpManualActivated = false;
            this.SealantManualModeToggleButton.OptionASelected = false;

            this.DrillMainPanel.Focus();
         }

         #endregion

         #region Sensor Controls

         if (RobotApplications.inspect == ParameterAccessor.Instance.RobotApplication)
         {
            this.sensorThicknessPending = false;
            this.newThicknessReading = false;
            this.sensorStressPending = false;
            this.newStressReading = false;
            this.sensorDirection = Directions.north;

            double latitude = ParameterAccessor.Instance.Latitude;
            if (double.IsNaN(latitude) == false)
            {
               this.SensorLatitudeTextPanel.ValueText = latitude.ToString("N4");
            }
            else
            {
               this.SensorLatitudeTextPanel.ValueText = "---";
            }

            double longitude = ParameterAccessor.Instance.Longitude;
            if (double.IsNaN(longitude) == false)
            {
               this.SensorLongitudeTextPanel.ValueText = longitude.ToString("N4");
            }
            else
            {
               this.SensorLongitudeTextPanel.ValueText = "---";
            }

            this.SensorDirectionTextPanel.ValueText = this.sensorDirection.ToString().ToUpper();
            this.SensorDirectionTextPanel.BackColor = Color.FromArgb(51, 51, 51);
            this.SensorDirectionTextPanel.Enabled = true;

            this.SensorDisplacementTextPanel.ValueText = "---";
            this.SensorGpsDateTextPanel.ValueText = "---";
            this.SensorGpsTimeTextPanel.ValueText = "---";

            this.SensorThicknessAcquireButton.Enabled = true;
            this.SensorThicknessReadingTextPanel.ValueText = "";

            this.SensorStressAcquireButton.Enabled = true;
            this.SensorStressReadingTextPanel.ValueText = "";

            if (0 != ParameterAccessor.Instance.LocationServer.Port)
            {
               LocationServer.Instance.Start(ParameterAccessor.Instance.LocationServer.Address, ParameterAccessor.Instance.LocationServer.Port);
            }
         }

         #endregion

         #region Camera Controls 

         this.RobotCamera1Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera1Button.Camera);
         this.RobotCamera2Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera2Button.Camera);
         this.RobotCamera3Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera3Button.Camera);
         this.RobotCamera4Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera4Button.Camera);
         this.RobotCamera5Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera5Button.Camera);
         this.RobotCamera6Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera6Button.Camera);
         this.RobotCamera7Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera7Button.Camera);
         this.RobotCamera8Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera8Button.Camera);
         this.RobotCamera9Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera9Button.Camera);
         this.RobotCamera10Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera10Button.Camera);
         this.RobotCamera11Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera11Button.Camera);
         this.RobotCamera12Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.RobotCamera12Button.Camera);
         this.LaunchCamera1Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.LaunchCamera1Button.Camera);
         this.LaunchCamera2Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.LaunchCamera2Button.Camera);
         this.LaunchCamera3Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.LaunchCamera3Button.Camera);
         this.LaunchCamera4Button.CenterLevel = (int)ParameterAccessor.Instance.GetLightLevel(this.LaunchCamera4Button.Camera);

         this.ClearCameraSelects(this.RobotCamera1Button);
         this.ClearCameraSelects(this.RobotCamera2Button);
         this.ClearCameraSelects(this.RobotCamera3Button);
         this.ClearCameraSelects(this.RobotCamera4Button);
         this.ClearCameraSelects(this.RobotCamera5Button);
         this.ClearCameraSelects(this.RobotCamera6Button);
         this.ClearCameraSelects(this.RobotCamera7Button);
         this.ClearCameraSelects(this.RobotCamera8Button);
         this.ClearCameraSelects(this.RobotCamera9Button);
         this.ClearCameraSelects(this.RobotCamera10Button);
         this.ClearCameraSelects(this.RobotCamera11Button);
         this.ClearCameraSelects(this.RobotCamera12Button);
         this.ClearCameraSelects(this.LaunchCamera1Button);
         this.ClearCameraSelects(this.LaunchCamera2Button);
         this.ClearCameraSelects(this.LaunchCamera3Button);
         this.ClearCameraSelects(this.LaunchCamera4Button);

         this.cameraSelectMode = CameraSelectModes.none;
         this.UpdateCameraHoldEnable();
         this.UpdateCameraSelectorColor();

         this.selectedLaunchCameraButton = null;
         this.selectedRobotCameraAButton = null;
         this.selectedRobotCameraBButton = null;

         this.UpdateCameraHoldEnable();

         #endregion

         NicBotComm.Instance.Start();

         ParameterAccessor.Instance.FrontDrill.ExtendedDistance.OperationalValue = ParameterAccessor.Instance.FrontDrill.ExtendedDistance.MinimumValue; // todo remove
         ParameterAccessor.Instance.FrontDrill.RotationSpeed.OperationalValue = ParameterAccessor.Instance.FrontDrill.RotationSpeed.MinimumValue; // todo remove
         ParameterAccessor.Instance.RearDrill.ExtendedDistance.OperationalValue = ParameterAccessor.Instance.RearDrill.ExtendedDistance.MinimumValue; // todo remove
         ParameterAccessor.Instance.RearDrill.RotationSpeed.OperationalValue = ParameterAccessor.Instance.RearDrill.RotationSpeed.MinimumValue; // todo remove

         this.SystemStatusTextBox.Text = "starting";
         this.SystemStatusTextBox.BackColor = Color.Yellow;

         this.UpdateTimer.Interval = 100;
         this.Process = this.ProcessWaitComm;
      }
Beispiel #17
0
      private void MovementManaulDisplayButton_Click(object sender, EventArgs e)
      {
         this.movementNonManualMode = NicBotComm.Instance.GetMovementMode();
         this.movementNonManualForwardMode = NicBotComm.Instance.GetMovementForwardMode();

         if (MovementForwardModes.normalAxial == this.movementNonManualForwardMode)
         {
            NicBotComm.Instance.SetMovementForwardMode(MovementForwardModes.normalAxial);
         }
         else
         {
            NicBotComm.Instance.SetMovementForwardMode(MovementForwardModes.circumferential);
         }

         NicBotComm.Instance.SetMovementMode(MovementModes.move);
            
         this.MovementManulPanel.Left = this.MovementMainPanel.Left;
         this.MovementManulPanel.Top = this.GetAbsoluteTop(this.MovementOffButton);
         this.MovementManulPanel.Visible = true;

         this.UpdateMovementControls();
      }
Beispiel #18
0
    // the Update loop contains a very simple example of moving the character around and controlling the animation
    void Update()
    {
        if (movementMode == MovementModes.None)
        {
            return;
        }

        // Crawling

        /*
         *      hit raycast looks above to see if anything above, just incase forced crouching is nessesary
         *      if not crawling + is grounded, and either the hit raycast collides, or if the movement mode is not no interaction and the player presses down, is grounded and is not pressing left or right
         *      Just added, check if anything below.. this helps with slopes... but may need some tweeking
         *      then begin crouching
         */
        RaycastHit2D hit     = Physics2D.Raycast(transform.position, Vector2.up, 1, LayerMask.GetMask("Default"), 0, 0);
        RaycastHit2D hitDown = Physics2D.Raycast(transform.position, Vector2.down, 0.6f, LayerMask.GetMask("Default"), 0, 0);

        if (movementMode != MovementModes.Crawling && _controller.isGrounded && hitDown.collider != null)
        {
            if ((hit.collider != null) || (movementMode != MovementModes.NoPlayerInteraction && _controller.isGrounded && Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == -1))
            {
                movementMode     = MovementModes.NoPlayerInteraction;
                startedCrouching = true;

                // Instant if forced
                if (hit.collider == null)
                {
                    animator.ResetTrigger("LayDown");
                    animator.SetTrigger("LayDown");
                }
                else
                {
                    animator.ResetTrigger("LayDownInstant");
                    animator.SetTrigger("LayDownInstant");
                }

                MHS.WaitRun(0.45f, () => {
                    movementMode     = MovementModes.Crawling;
                    startedCrouching = false;
                });
            }
        }

        if (movementMode == MovementModes.Normal || movementMode == MovementModes.NoPlayerInteraction)
        {
            if (_controller.isGrounded)
            {
                _velocity.y = 0;
            }

            if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == 1)
            {
                normalizedHorizontalSpeed = 1;
                directionFacing           = 1;

                //if( _controller.isGrounded )
                //	_animator.Play( Animator.StringToHash( "Run" ) );
            }
            else if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == -1)
            {
                directionFacing           = -1;
                normalizedHorizontalSpeed = -1;

                //if( _controller.isGrounded )
                //	_animator.Play( Animator.StringToHash( "Run" ) );
            }
            else
            {
                normalizedHorizontalSpeed = 0;

                //if( _controller.isGrounded )
                //	_animator.Play( Animator.StringToHash( "Idle" ) );
            }


            // we can only jump whilst grounded
            if (movementMode != MovementModes.NoPlayerInteraction && _controller.isGrounded && Input.GetButtonDown("Jump"))
            {
                AudioManager.instance.PlaySFX("Jump");
                _velocity.y = Mathf.Sqrt(jumpHeight * -gravity);

                MHS.RunFor(0.2f, i => {
                    if (Input.GetButton("Jump"))
                    {
                        _velocity.y = Mathf.Sqrt(jumpHeight * -gravity);
                    }
                });
            }


            // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
            var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping;             // how fast do we change direction?
            _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);

            // apply gravity before moving
            _velocity.y += gravity * Time.deltaTime;

            // if holding down bump up our movement amount and turn off one way platform detection for a frame.
            // this lets us jump down through one way platforms
            if (_controller.isGrounded && Input.GetKey(KeyCode.DownArrow))
            {
                _velocity.y *= 3f;
                _controller.ignoreOneWayPlatformsThisFrame = true;
            }

            // Do the moving
            _controller.move(_velocity * Time.deltaTime);
        }
        else if (movementMode == MovementModes.SwimmingSurface)
        {
            float yPosOffset = -0.05f;
            if (enteringWater)
            {
                if (!startSurfaceing)
                {
                    _controller.move(_velocity * Time.deltaTime);
                }
                else
                {
                    _velocity = new Vector3(_velocity.x, _velocity.y += 20 * Time.deltaTime, _velocity.z);
                    _controller.move(_velocity * Time.deltaTime);
                }

                if (transform.position.y < topOfWater - 0.3f)
                {
                    startSurfaceing = true;
                }

                if (startSurfaceing && transform.position.y >= topOfWater + yPosOffset)
                {
                    startSurfaceing    = false;
                    paddleingRotation  = 0;
                    enteringWater      = false;
                    _velocity          = new Vector3(_velocity.x, 0, _velocity.z);
                    transform.position = new Vector3(transform.position.x, topOfWater + yPosOffset, transform.position.z);
                }
            }

            if (!enteringWater)
            {
                transform.position = new Vector3(transform.position.x, topOfWater + yPosOffset, transform.position.z);

                float rotateSpeed = 240;
                if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == 1)
                {
                    if (paddleingRotation > 0)
                    {
                        paddleingRotation /= 4;
                    }
                    paddleingRotation -= Time.deltaTime * rotateSpeed;

                    directionFacing           = 1;
                    normalizedHorizontalSpeed = 1;
                }
                else if (movementMode != MovementModes.NoPlayerInteraction && Input.GetAxisRaw("Horizontal") == -1)
                {
                    if (paddleingRotation < 0)
                    {
                        paddleingRotation /= 4;
                    }
                    paddleingRotation += Time.deltaTime * rotateSpeed;

                    directionFacing           = -1;
                    normalizedHorizontalSpeed = -1;
                }
                else
                {
                    if (paddleingRotation < Time.deltaTime * rotateSpeed)
                    {
                        paddleingRotation += Time.deltaTime * rotateSpeed;
                    }
                    if (paddleingRotation > Time.deltaTime * rotateSpeed)
                    {
                        paddleingRotation -= Time.deltaTime * rotateSpeed;
                    }

                    normalizedHorizontalSpeed = 0;
                }

                paddleingRotation  = Mathf.Clamp(paddleingRotation, -45f, 45f);
                transform.rotation = Quaternion.Euler(0, 0, paddleingRotation);

                var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping;                 // how fast do we change direction?
                _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed / 1.5f, Time.deltaTime * smoothedMovementFactor);
                _velocity.y = 0;

                if (Input.GetButtonDown("Jump"))
                {
                    MugHeadStudios.MHS.RunFor(0.1f, i => {
                        transform.rotation = Quaternion.Euler(0, 0, paddleingRotation * (1 - i));
                    }, () => {
                        transform.rotation = Quaternion.identity;
                    });
                    _velocity.y  = Mathf.Sqrt(2f * jumpHeight * -gravity);
                    movementMode = MovementModes.Normal;
                    Splash();
                }

                _controller.move(_velocity * Time.deltaTime);
            }
        }
        else if (movementMode == MovementModes.Crawling)
        {
            _velocity.y -= 15 * Time.deltaTime;

            if (Input.GetAxisRaw("Horizontal") == 1)
            {
                directionFacing = 1;
                _velocity.x     = 2;
            }
            else if (Input.GetAxisRaw("Horizontal") == -1)
            {
                directionFacing = -1;
                _velocity.x     = -2;
            }
            else
            {
                _velocity.x = 0;
            }

            _controller.move(_velocity * Time.deltaTime);

            hitDown = Physics2D.Raycast(transform.position, Vector2.down, 0.6f, LayerMask.GetMask("Default"), 0, 0);

            if (Input.GetAxisRaw("Vertical") != -1 || hitDown.collider == null)
            {
                // Coming up from crouch, check above head first
                hit = Physics2D.Raycast(transform.position, Vector2.up, 1, LayerMask.GetMask("Default"), 0, 0);
                if (hit.collider == null)
                {
                    movementMode = MovementModes.NoPlayerInteraction;
                    MHS.WaitRun(0.4f, () => {
                        movementMode = MovementModes.Normal;
                    });
                }
            }
        }

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;

        // Animation
        animator.SetFloat("Running", (_controller.isGrounded && movementMode == MovementModes.Normal && Input.GetAxisRaw("Horizontal") != 0) ? 1 : 0);
        animator.SetBool("IsGrounded", _controller.isGrounded);
        animator.SetBool("IsPaddleing", (movementMode == MovementModes.SwimmingSurface));
        animator.SetBool("IsCrawling", (startedCrouching || movementMode == MovementModes.Crawling));
        animator.SetBool("CrawlingMoving", (movementMode == MovementModes.Crawling && Mathf.Abs(_velocity.x) > 0));
        animator.SetBool("PaddleingSwimming", (movementMode == MovementModes.SwimmingSurface && Input.GetAxisRaw("Horizontal") != 0));

        // Direction
        if (directionFacing == 1)
        {
            transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
        }
        else if (directionFacing == -1)
        {
            transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
        }
    }
Beispiel #19
0
 public void SetMovementMode(MovementModes mode)
 {
    RobotCommBus.Instance.SetMovementMode(mode);
 }