コード例 #1
0
    void UpdateLedgeGrab()
    {
        // Need to make a non-standard update to limit how people can look around while hanging.
        StandardCameraUpdate();

        if (moveDirection.y != 0)
        {
            moveDirection.y -= friction * Time.deltaTime;
            moveDirection.y  = Mathf.Clamp(moveDirection.y, 0, 100);
        }

        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            canGrabLedge = false;
            motorState   = MotorStates.Default;
            climbTime    = 0f;
        }

        if (Input.GetButton("Jump"))
        {
            // Muscle up
            motorState = MotorStates.MusclingUp;
            climbTime  = 0f;
        }
    }
コード例 #2
0
    // UpdateJump updates the gravity, but more importantly it checks if the player is able to do specific,
    // vertical movement related actions such as Wall Running, or Wall Climbing.
    void UpdateJump()
    {
        StandardCameraUpdate();

        // Do a wall run check and change state if successful.
        wallHit = DoWallRunCheck();
        if (wallHit.collider != null)
        {
            motorState = MotorStates.Wallrunning;
            return;
        }

        // Do a wall climb check and I need to clean up these hits.
        RaycastHit hit = DoWallClimbCheck(new Ray(transform.position,
                                                  transform.TransformDirection(Vector3.forward).normalized * 0.1f));

        if (hit.collider != null)
        {
            motorState = MotorStates.Climbing;
            return;
        }

        // Now, if we've actually gotten this far...Sheesh.
        // Update gravity, since there's no other movement direction to worry about
        moveDirection.y -= Gravity * Time.deltaTime;

        if (controller.isGrounded)
        {
            motorState = MotorStates.Default;
        }
    }
コード例 #3
0
        public void GetDataFromController()
        {
            if (!api.IsConnected)
            {
                logger.Info("Controller not connected");
            }
            else
            {
                acsUtils.ReadInt("MFLAGS", (int)AcsAxisId);
                UpdateFaultFromController();
                MotorStates motorState = api.GetMotorState(AcsAxisId);
                Enabled = (motorState & MotorStates.ACSC_MST_ENABLE) == MotorStates.ACSC_MST_ENABLE;
                bool flag = (motorState & MotorStates.ACSC_MST_MOVE) != MotorStates.ACSC_MST_MOVE &&
                            !ScanningBufferRun;
                if (initializing)
                {
                    InitializingBufferRun = bufferHelper.IsProgramRunning((ProgramBuffer)HomeBuffer);
                    flag = flag && !InitializingBufferRun;
                }

                Idle = flag;
                if (Idle && (moving || stopping || aborting))
                {
                    MotionEnded(true);
                }
                Position        = api.GetRPosition(AcsAxisId);
                CurrentVelocity = Math.Round(api.GetRVelocity(AcsAxisId));
                Ready           = Enabled && Homed;
            }
        }
コード例 #4
0
        private void RefleshRobotUi()
        {
            try
            {
                foreach (var item in _rack.Motion.Motors)
                {
                    MotorStates State = _rack.Motion.GetRobotState(item);
                    switch (item.Id)
                    {
                    case Axis.ACSC_AXIS_0: buttonEableZ.Text = Convert.ToBoolean(State & MotorStates.ACSC_MST_ENABLE) ? "Disable" : "Enable"; break;

                    case Axis.ACSC_AXIS_1: buttonEableX1.Text = Convert.ToBoolean(State & MotorStates.ACSC_MST_ENABLE) ? "Disable" : "Enable"; break;

                    case Axis.ACSC_AXIS_2: buttonEableX2.Text = Convert.ToBoolean(State & MotorStates.ACSC_MST_ENABLE) ? "Disable" : "Enable"; break;

                    case Axis.ACSC_AXIS_3: buttonEableY.Text = Convert.ToBoolean(State & MotorStates.ACSC_MST_ENABLE) ? "Disable" : "Enable"; break;

                    case Axis.ACSC_AXIS_4: buttonEableR.Text = Convert.ToBoolean(State & MotorStates.ACSC_MST_ENABLE) ? "Disable" : "Enable"; break;

                    default:
                        break;
                    }
                }
                buttonG1TightOrLoose.Text = _rack.EcatIo.GetInput(Input.Gripper01Tight) ? "G1Open" : "G1Close";
                buttonG2TightOrLoose.Text = _rack.EcatIo.GetInput(Input.Gripper02Tight) ? "G2Open" : "G2Close";
                buttonEableG1.Text        = _rack.Steppers.GetStatus(StepperMotor.One, StatusCode.Enabled) ? "Disable" : "Enable";
                buttonEableG2.Text        = _rack.Steppers.GetStatus(StepperMotor.Two, StatusCode.Enabled) ? "Disable" : "Enable";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #5
0
 // Activates ledge grab
 // TODO: Requires user to be jumping or climbing, should allow for falling as well.
 void LedgeGrab()
 {
     if (canGrabLedge &&
         (motorState == MotorStates.Jumping || motorState == MotorStates.Climbing) &&
         Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward).normalized, 1f))
     {
         motorState = MotorStates.Ledgegrabbing;
     }
 }
コード例 #6
0
      public FeederMotorParameters()
      {
         this.Location = "";

         this.State = default(MotorStates);
         this.Direction = default(MotorDirections);
         this.PositivePusher = default(bool);
         this.PositionInversion = default(bool);
      }
コード例 #7
0
 public void Set(MovementMotorParameters parameters)
 {
    this.Location = parameters.Location;
    this.State = parameters.State;
    this.Direction = parameters.Direction;
    this.AxialMode = parameters.AxialMode;
    this.CircumferentialMode = parameters.CircumferentialMode;
    this.CornerAxialMode = parameters.CornerAxialMode;
    this.LaunchAxialMode = parameters.LaunchAxialMode;
 }
コード例 #8
0
    void StopWallRun()
    {
        if (motorState == MotorStates.Wallrunning)
        {
            canWallRun = false;
        }

        wallRunTime = 0.0f;
        motorState  = MotorStates.Default;
    }
コード例 #9
0
        public void SwitchToNewState(MotorStates newStateType)
        {
            if (currentStateType != newStateType)
            {
                currentStateType = newStateType;

                currentStateClass.StateExit();
                currentStateClass = stateClassLookup[newStateType];
                currentStateClass.StateEntry();
            }
        }
コード例 #10
0
      public MovementMotorParameters()
      {
         this.Location = "";

         this.State = default(MotorStates);
         this.Direction = default(MotorDirections);
         this.AxialMode = default(MovementForwardControls); ;
         this.CircumferentialMode = default(MovementForwardControls); ;
         this.CornerAxialMode = default(MovementForwardControls); ;
         this.LaunchAxialMode = default(MovementForwardControls); ;
      }
コード例 #11
0
    }                                                     //The component that does the raycast checks.


    #region Public
    public void SwitchToNewState(MotorStates newStateType) //This method tells the class to change to a state
    {
        if (currentStateType != newStateType)              //Only change the state when we're not already there
        {
            currentStateType = newStateType;

            currentStateClass.StateExit();  //Tell the current state we're exiting, so it can perform clean ups.
            currentStateClass = stateClassLookup[newStateType];
            currentStateClass.StateEntry(); //Tell the new state we're entering, so it can perform initializations.
        }
    }
コード例 #12
0
    void UpdateWallRun()
    {
        if (!controller.isGrounded && canWallRun && wallRunTime < wallRunMaxTime)
        {
            // Always update the wallhit, because we run past the edge of a wall. This keeps us
            // from floating off in to the ether.
            wallHit = DoWallRunCheck();
            if (wallHit.collider == null)
            {
                StopWallRun();
                return;
            }

            motorState = MotorStates.Wallrunning;
            float previousJumpHeight = moveDirection.y;

            Vector3 crossProduct = Vector3.Cross(Vector3.up, wallHit.normal);

            Quaternion lookDirection = Quaternion.LookRotation(crossProduct);
            transform.rotation = Quaternion.Slerp(transform.rotation, lookDirection, 3.5f * Time.deltaTime);

            //camera.transform.Rotate(new Vector3(0f,0f,20f * Time.deltaTime));

            moveDirection = crossProduct;
            moveDirection.Normalize();
            moveDirection *= BaseSpeed + (RunSpeedIncrease * (moveDownTime / RampUpTime));

            if (wallRunTime == 0.0f)
            {
                // increase vertical movement.
                moveDirection.y = JumpSpeed / 4;
            }
            else
            {
                moveDirection.y  = previousJumpHeight;
                moveDirection.y -= (Gravity / 4) * Time.deltaTime;
            }

            wallRunTime += Time.deltaTime;
            //Debug.Log("Wall run time: " + wallRunTime);

            if (wallRunTime > wallRunMaxTime)
            {
                canWallRun = false;
                Debug.Log("Max wall run time hit.");
            }
        }
        else
        {
            StopWallRun();
        }
    }
コード例 #13
0
    // Does a raycast forward to check for a wall. If found, it looks up and climbs it.
    void UpdateWallClimb()
    {
        if (!moveKeyDown)
        {
            climbTime = 0.0f;
            if (motorState == MotorStates.Climbing)
            {
                canClimb = false;
            }
            motorState = MotorStates.Default;
            return;
        }

        Ray forwardRay = new Ray(transform.position, transform.TransformDirection(Vector3.forward).normalized);

        forwardRay.direction *= 0.1f;

        RaycastHit hit = DoWallClimbCheck(forwardRay);

        if (canClimb && hit.collider != null &&
            climbTime < 0.5f && Vector3.Angle(forwardRay.direction, hit.normal) > 165)
        {
            climbTime += Time.deltaTime;

            // Look up. Disabled for now.
            Quaternion lookDirection = Quaternion.LookRotation(hit.normal * -1);
            transform.rotation = Quaternion.Slerp(transform.rotation, lookDirection, 3.5f * Time.deltaTime);
            //camera.transform.Rotate(-85f * (climbTime / 0.5f), 0f, 0f); //            ^ Magic number for tweaking look time

            // Move up.
            moveDirection += transform.TransformDirection(Vector3.up);
            moveDirection.Normalize();
            moveDirection *= BaseSpeed;

            motorState = MotorStates.Climbing;
        }
        else
        {
            if (motorState == MotorStates.Climbing)
            {
                canClimb = false;
            }
            climbTime  = 0f;
            motorState = MotorStates.Default;
        }
    }
コード例 #14
0
    void MuscleUp()
    {
        Ray ray = new Ray(transform.position, transform.TransformDirection(Vector3.forward));

        ray.direction.Normalize();
        ray.origin = ray.origin - new Vector3(0f, 1f, 0f);

        if (Physics.Raycast(ray.origin, ray.direction, 1f))
        {
            moveDirection = transform.TransformDirection(Vector3.up + Vector3.forward);
            moveDirection.Normalize();
            moveDirection *= BaseSpeed;
        }
        else
        {
            motorState = MotorStates.Default;
        }
    }
コード例 #15
0
    void Awake()
    {
        //Reference
        rb        = GetComponent <Rigidbody2D>();
        raycaster = GetComponent <MotorRaycaster>();
        Feedbacks = GetComponentInChildren <Player2DFeedbacks>();

        //Initialize various variables
        status           = new MotorStatus();
        stateClassLookup = new Dictionary <MotorStates, MotorStateBase> //Store all the FSM classes using their common base class
        {
            { MotorStates.OnGround, new MotorState_MoveOnGround(this, Feedbacks) },
            { MotorStates.Aerial, new MotorState_Aerial(this, Feedbacks) },
            { MotorStates.WallClimb, new MotorState_WallClimb(this, Feedbacks) },
            { MotorStates.Hurt, new MotorState_Hurt(this, Feedbacks) },
        };

        currentStateType  = MotorStates.OnGround;
        currentStateClass = stateClassLookup[currentStateType];
    }
コード例 #16
0
    private void Awake()
    {
        //Reference
        Rb               = GetComponent <Rigidbody>();
        Raycaster        = GetComponent <MotorRaycaster>();
        feedback         = GetComponentInChildren <PlayerFeedbacks>();
        cameraController = GetComponent <Player3rdPersonCamera>();

        //Initialize
        Status           = new PlayerStatus();
        stateClassLookup = new Dictionary <MotorStates, MotorStateBase>
        {
            { MotorStates.OnGround, new MotorState_MoveOnGround(this, feedback) },
            { MotorStates.Aerial, new MotorState_Aerial(this, feedback) },
            //{MotorStates.Hurt,      new MotorState_Hurt(this, Feedbacks)},
        };

        currentStateType  = MotorStates.OnGround;
        currentStateClass = stateClassLookup[currentStateType];
    }
コード例 #17
0
    // Default movement update for when someone's just on the ground, running and such.
    void UpdateDefault()
    {
        // Update camera and general house keeping.
        StandardCameraUpdate();

        // Update momentum amount based on continuous run time.
        moveKeyDown = Input.GetKey(KeyCode.W);
        if (moveKeyDown && moveDownTime <= RampUpTime)
        {
            moveDownTime += Time.deltaTime;
            if (moveDownTime > RampUpTime)
            {
                moveDownTime = RampUpTime;
            }
        }

        if (controller.isGrounded)
        {
            // Stop  momentum only if grounded. Can't slow down while airborne.
            if (!moveKeyDown)
            {
                moveDownTime = 0f;
            }

            // Make sure some things get reset now that we've touched down and can recover.
            canClimb     = true;
            canWallRun   = true;
            canGrabLedge = true;

            // Update move direction with standard forward, back, and strafe controls.
            moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection.Normalize();

            moveDirection *= BaseSpeed + (RunSpeedIncrease * (moveDownTime / RampUpTime));

            // slow to a stop if no input
            if ((moveDirection == Vector3.zero && lastDirection != Vector3.zero))
            {
                if (lastDirection.x != 0)
                {
                    moveDirection.x = DoSlowDown(lastDirection.x);
                }

                if (lastDirection.z != 0)
                {
                    moveDirection.z = DoSlowDown(lastDirection.z);
                }
            }

            // Debating using a controller function or class to handle this, but for now...
            if (Input.GetButton("Jump"))
            {
                motorState      = MotorStates.Jumping;
                moveDirection.y = JumpSpeed;
            }
        }

        // Keeping this here right now in case I don't feel the need for a falling function.
        moveDirection.y -= Gravity * Time.deltaTime;
    }
コード例 #18
0
 public void Set(FeederMotorParameters parameters)
 {
    this.Location = parameters.Location;
    this.State = parameters.State;
    this.Direction = parameters.Direction;
 }