Esempio n. 1
0
    void updateJUMP()
    {
        swingtimer += Time.deltaTime;

        horizontalDirection  = new Vector3(moveDirection.x, 0, moveDirection.z);
        horizontalDirection -= Time.deltaTime * DRAG * horizontalDirection;

        if (Input.GetKey(KeyCode.W))
        {
            if (horizontalDirection.magnitude < MAXAIRCONTROL)
            {
                horizontalDirection += player.forward * Time.deltaTime * AIRACCEL;
            }
            //horizontalDirection = Vector3.ClampMagnitude(horizontalDirection, MAXAIRCONTROL);
        }
        else if (Input.GetKey(KeyCode.S))
        {
            if (horizontalDirection.magnitude < MAXAIRCONTROL)
            {
                horizontalDirection += player.forward * Time.deltaTime * -AIRACCEL;
            }
            //horizontalDirection = Vector3.ClampMagnitude(horizontalDirection, MAXAIRCONTROL);
        }
        moveDirection.x = horizontalDirection.x;
        moveDirection.z = horizontalDirection.z;

        if (Input.GetKey(KeyCode.A))
        {
            player.Rotate(new Vector3(0, 1, 0), -AIRTURNSPEED * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.D))
        {
            player.Rotate(new Vector3(0, 1, 0), AIRTURNSPEED * Time.deltaTime);
        }

        //apply gravity and terminal velocity
        moveDirection.y -= GRAVITY * Time.deltaTime;
        moveDirection.y  = Mathf.Max(TERMINALVELOCITY, moveDirection.y);

        //move the dude
        controller.Move(moveDirection * Time.deltaTime);

        //land
        if ((controller.collisionFlags & CollisionFlags.Below) != 0)
        {
            state.ChangeState(enterGROUND, updateGROUND, exitGROUND);
            return;
        }
    }
Esempio n. 2
0
 void updateStart()
 {
     if (Input.GetKey(KeyCode.Return))
     {
         state.ChangeState(enterHeavyJump, updateHeavyJump, exitHeavyJump);
     }
 }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        controller          = gameObject.GetComponent <CharacterController>();
        moveDirection       = Vector3.zero;
        horizontalDirection = Vector3.zero;

        state = new ImmediateStateMachine();
        state.ChangeState(enterGROUND, updateGROUND, exitGROUND);
    }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     wall  = "right";
     hit   = new RaycastHit();
     state = new ImmediateStateMachine();
     state.ChangeState(enterStart, updateStart, exitStart);
     xVel       = 0;
     yVel       = 0;
     truecamera = camera;
 }
Esempio n. 5
0
    void Start()
    {
        stateMachine.ChangeState(enterGROUNDED, updateGROUNDED, exitGROUNDED);
        GameEventManager.GameStart += GameStart;
        GameEventManager.GameOver  += GameOver;

        // Assign body parts to variables;
        // -> could also have these as properties you set in editor
        // -> could also have used Transform.Find to only search in the children of this object
        head = GameObject.Find("Head");
        body = GameObject.Find("Body");

        gameObject.SetActive(false);
    }
 //-----------------
 // GROUNDED state
 //-----------------
 void switchToGroundedFSM()
 {
     stateMachine.ChangeState(enterGROUNDED, updateGROUNDED, exitGROUNDED);
 }