Beispiel #1
0
 private void GroundCheck()
 {
     if (InContactWithSurface())
     {
         m_JumpState = JumpStates.Grounded;
         Debug.Log("Going to Grounded!");
     }
 }
Beispiel #2
0
        // Use this for initialization
        private void Start()
        {
            m_WheelMeshLocalRotations = new Quaternion[4];
            for (int i = 0; i < 4; i++)
            {
                m_WheelMeshLocalRotations[i] = m_WheelMeshes[i].transform.localRotation;
            }
            m_WheelColliders[0].attachedRigidbody.centerOfMass = m_CentreOfMassOffset;

            m_MaxHandbrakeTorque = float.MaxValue;

            m_Rigidbody     = GetComponent <Rigidbody>();
            m_CurrentTorque = m_FullTorqueOverAllWheels - (m_TractionControl * m_FullTorqueOverAllWheels);

            m_JumpState = JumpStates.Grounded;

            m_LeftBoostBurn.enableEmission  = false;
            m_RightBoostBurn.enableEmission = false;

            m_AngularDrag = m_Rigidbody.angularDrag;
        }
Beispiel #3
0
    void JumpLogic()
    {
        switch (States)
        {
        case JumpStates.NOTSTARTED:
            if (DistBetween(player.position, WaypointList[0].position) < 2)     //check distance between player and waypoint
            {
                Debug.Log("Near");
                if (CheckWaypoint(currentWayPoint))     //if facing?
                {
                    Debug.Log("facing and near");
                    if (GamepadManager.buttonADown)     //if player jumps?
                    {
                        Debug.Log("Jumped");
                        SplineJump(0);                                                   //moves the spline root to the correct positons
                        splineScript.FollowSpline();                                     //makes the spline move
                        currentWayPoint++;                                               //sets to ext waypoint
                        freezeMovement        = true;                                    //then you freeze
                        moveScript.charStates = MovementController.States.sequencedjump; // and set its state
                        States = JumpStates.STARTING;
                    }
                }
            }
            break;

        case JumpStates.STARTING:
            if (DistBetween(player.position, WaypointList[currentWayPoint].position) < 5)
            {
                if (CheckWaypoint(currentWayPoint))
                {
                    if (GamepadManager.buttonADown)
                    {
                        SplineJump(currentWayPoint);
                        splineScript.FollowSpline();
                        currentWayPoint++;
                    }
                }
            }
            if ((currentWayPoint + 2) == WaypointList.Count)
            {
                States = JumpStates.ENDING;
            }
            break;

        case JumpStates.JUMPING:
            break;

        case JumpStates.ENDING:
            if (DistBetween(player.position, WaypointList[currentWayPoint].position) < 5)
            {
                if (CheckWaypoint(currentWayPoint))
                {
                    if (GamepadManager.buttonADown)
                    {
                        SplineJump(currentWayPoint);
                        splineScript.FollowSpline();
                        freezeMovement  = false;    //then you unfreeze
                        currentWayPoint = 0;
                        States          = JumpStates.NOTSTARTED;
                        // moveScript.charStates = MovementController.States.sequencedjump; // and set its state

                        //   currentWayPoint++;
                    }
                }
            }
            break;
        }
    }
 void FixedUpdate()
 {
     jumpMachine.Update();
     currentState = jumpMachine.currentState;
 }
Beispiel #5
0
    void JumpLogic()
    {
        switch(States)
        {
            case JumpStates.NOTSTARTED:
                if (DistBetween(player.position, WaypointList[0].position) < 2) //check distance between player and waypoint
                {
                    Debug.Log("Near");
                    if (CheckWaypoint(currentWayPoint)) //if facing?
                    {
                        Debug.Log("facing and near");
                        if (GamepadManager.buttonADown) //if player jumps?
                        {
                            Debug.Log("Jumped");
                            SplineJump(0); //moves the spline root to the correct positons
                            splineScript.FollowSpline(); //makes the spline move
                            currentWayPoint++; //sets to ext waypoint
                            freezeMovement = true; //then you freeze
                            moveScript.charStates = MovementController.States.sequencedjump; // and set its state
                            States = JumpStates.STARTING;
                        }
                    }
                }
                break;
            case JumpStates.STARTING:
                if(DistBetween(player.position,WaypointList[currentWayPoint].position) <5)
                {
                    if(CheckWaypoint(currentWayPoint))
                    {
                        if(GamepadManager.buttonADown)
                        {
                            SplineJump(currentWayPoint);
                            splineScript.FollowSpline();
                            currentWayPoint++;
                        }
                    }
                }
                if((currentWayPoint+2) == WaypointList.Count)
                {
                    States = JumpStates.ENDING;
                }
                break;
            case JumpStates.JUMPING:
                break;
            case JumpStates.ENDING:
                if (DistBetween(player.position, WaypointList[currentWayPoint].position) < 5)
                {
                    if (CheckWaypoint(currentWayPoint))
                    {
                        if (GamepadManager.buttonADown)
                        {
                            SplineJump(currentWayPoint);
                            splineScript.FollowSpline();
                            freezeMovement = false; //then you unfreeze
                            currentWayPoint = 0;
                            States = JumpStates.NOTSTARTED;
                           // moveScript.charStates = MovementController.States.sequencedjump; // and set its state

                            //   currentWayPoint++;
                        }
                    }
                }
                break;
        }
    }
Beispiel #6
0
    // Update is called once per frame
    void FixedUpdate()
    {
        StartCoroutine(LateFixedUpdate());

        #region gravity
        if (!grounded)
        {
            if (rb.velocity.y < 0) //if falling
            {
                if (rb.velocity.y < -2f)
                {
                    rb.AddForce(Vector3.down * normalGravity * 7f);
                }
                else
                {
                    rb.AddForce(Vector3.down * normalGravity * 1.5f);
                }

                jumpState = JumpStates.falling;
            }
            else if (rb.velocity.y > 0 && !Input.GetKey(KeyCode.Space)) //if rising and you let go spacebar
            {
                if (rb.velocity.y > 2)
                {
                    rb.AddForce(Vector3.down * normalGravity * fallMultiplier);
                }
                else
                {
                    rb.AddForce(Vector3.down * normalGravity * fallMultiplier * 0.2f);
                }
                jumpState = JumpStates.shortJump;
            }
            else if (rb.velocity.y > 0 && rb.velocity.y < 0.5f) //if rising and before you reach yspeed of 2
            {
                rb.AddForce(Vector3.down * normalGravity * 0.05f);
                jumpState = JumpStates.second;
            }
            else if (rb.velocity.y > 0 && rb.velocity.y < 1) //if rising and before you reach yspeed of 2
            {
                rb.AddForce(Vector3.down * normalGravity * 0.13f);
                jumpState = JumpStates.third;
            }
            else if (rb.velocity.y > 0 && rb.velocity.y < 2) //if rising and before you reach yspeed of 2
            {
                rb.AddForce(Vector3.down * normalGravity * 0.2f);
                jumpState = JumpStates.second;
            }
            else if (rb.velocity.y > 2) //if rising and after you reach 2
            {
                rb.AddForce(Vector3.down * normalGravity * 0.7f);
                jumpState = JumpStates.first;
            }
            else //every other time
            {
                rb.AddForce(Vector3.down * normalGravity);
                jumpState = JumpStates.Else;
            }
        }
        #endregion

        if (grounded)
        {
            //gasParticles.localRotation = Quaternion.Euler(0, 180, 0);
            jumpState = JumpStates.Else;
        }


        #region y clamp to stop ground penetration
        if (!grounded && rb.velocity.y < 0)
        {
            if (Physics.Raycast(heightRays[0].position, heightRays[0].up * -1, out heightHits[0], restingHeight * 3f, mask))
            {
                Debug.DrawRay(heightRays[0].position, heightRays[0].up * -1 * heightHits[0].distance, Color.yellow);
                rayHit = true;
            }
            else
            {
                Debug.DrawRay(heightRays[0].position, heightRays[0].up * -1 * restingHeight * 3f, Color.red);
                rayHit = false;
            }
        }
        #endregion

        transform.position = new Vector3(transform.position.x, Mathf.Clamp(transform.position.y, heightHits[0].point.y + heightOffset, transform.position.y), transform.position.z);

        if (transform.position.y <= heightHits[0].point.y + heightOffset + snapHeight)
        {
            if (jumpState == JumpStates.falling)
            {
                Vector3 position = transform.position;
                grounded           = true;
                rb.velocity        = new Vector3(rb.velocity.x, 0, rb.velocity.z);
                position.y         = heightHits[0].point.y;
                transform.position = position;
                transform.up       = heightHits[0].normal;
            }
        }
        else
        {
            grounded = false;
        }


        #region jump request
        if (jumpRequest)
        {
            jumpRequest = false;
            rb.AddForce(Vector3.up * jumpStrength, ForceMode.Impulse);
            grounded = false;
        }
        else
        {
            //Vector3 boxCenter = transform.position + new Vector3(0,body.size.y/2, 0);
            //Collider[] co = new Collider[2];
            //co = Physics.OverlapBox(boxCenter, body.size * 0.5f, transform.rotation, mask);
            //if (co.Length > 0)
            //{
            //    grounded = true;
            //}
            //else
            //{
            //    grounded = false;
            //}
        }
        #endregion
    }
Beispiel #7
0
        // Logic controlling car jumping state machine
        private void Jump(float jump, float steer, float forward, float rollbrake)
        {
            switch (m_JumpState)
            {
            case JumpStates.Grounded:
                if (jump > 0.0f && !m_JumpPressed)
                {
                    m_JumpTime  = Time.time;
                    m_JumpState = JumpStates.FirstJumpSetup;
                    Debug.Log("Going to FirstJumpSetup!");
                }
                else if (!InContactWithSurface())
                {
                    m_JumpState = JumpStates.Floating;
                    Debug.Log("Going to Floating!");
                }
                break;

            case JumpStates.Floating:
                MoveInAir(steer, forward, rollbrake);
                if (jump > 0.0f && !m_JumpPressed)
                {
                    m_JumpState = JumpStates.SecondJumpInit;
                    Debug.Log("Going to SecondJumpInit!");
                }
                GroundCheck();
                break;

            case JumpStates.FirstJumpSetup:
                if (jump > 0f && !m_JumpPressed)
                {
                    m_PendingJump = true;
                }

                if ((Time.time - m_JumpTime) <= m_JumpSetupTime)
                {
                    m_Rigidbody.AddForce(transform.up * m_JumpSetupForce * Time.deltaTime,
                                         ForceMode.Impulse);
                }
                else
                {
                    if (m_PendingJump)
                    {
                        m_PendingJump = false;
                        m_JumpState   = JumpStates.SecondJumpInit;
                        Debug.Log("Going to SecondJumpInit!");
                    }
                    else
                    {
                        m_JumpState = JumpStates.FirstJump;
                        Debug.Log("Going to FirstJump!");
                    }
                }
                break;

            case JumpStates.FirstJump:
                MoveInAir(steer, forward, rollbrake);
                if ((Time.time - m_JumpTime) > m_FirstJumpTime)
                {
                    m_JumpState = JumpStates.InAirAlive;
                    Debug.Log("Going to InAirAlive!");
                }
                else if (m_JumpPressed)
                {
                    if (jump > 0.0f)
                    {
                        m_Rigidbody.AddForce(transform.up * m_JumpForce * Time.deltaTime,
                                             ForceMode.Impulse);
                    }
                    else
                    {
                        m_JumpState = JumpStates.InAirAlive;
                        Debug.Log("Going to InAirAlive!");
                    }
                }
                else
                {
                    if (jump > 0.0f)
                    {
                        m_JumpState = JumpStates.SecondJumpInit;
                        Debug.Log("Going to SecondJumpInit!");
                    }
                    else
                    {
                        m_JumpState = JumpStates.InAirAlive;
                        Debug.Log("Going to InAirAlive!");
                    }
                }
                GroundCheck();
                break;

            case JumpStates.SecondJumpInit:
                if (Mathf.Abs(forward) < 0.1f && Mathf.Abs(steer) < 0.1f)
                {
                    m_Rigidbody.AddForce(
                        transform.up * 10000f, ForceMode.Impulse);
                    m_JumpState = JumpStates.InAirDead;
                    Debug.Log("Going to InAirDead!");
                }
                else
                {
                    // init
                    m_Rigidbody.useGravity  = false;
                    m_Rigidbody.angularDrag = 0.2f;
                    Vector3 velocity = m_Rigidbody.velocity;
                    velocity.y           = 0f;
                    m_Rigidbody.velocity = velocity;
                    Vector3 torqDir = new Vector3(
                        forward,
                        0f,
                        -steer);
                    m_Rigidbody.AddRelativeTorque(
                        torqDir * m_JumpFlipFactor, ForceMode.Impulse);

                    /*
                     * Vector3 forceDir = new Vector3(
                     *  steer,
                     *  0f,
                     *  forward
                     *  );
                     * m_Rigidbody.AddRelativeForce(
                     *  forceDir*20000f, ForceMode.Impulse);
                     */
                    m_JumpState = JumpStates.SecondJump;
                    m_JumpTime  = Time.time;
                    Debug.Log("Going to SecondJump!");
                }
                break;

            case JumpStates.SecondJump:
                if ((Time.time - m_JumpTime) > m_SecondJumpTime)
                {
                    m_JumpState = JumpStates.SecondJumpFinish;
                    Debug.Log("Going to SecondJumpFinish!");
                }
                break;

            case JumpStates.SecondJumpFinish:
                m_Rigidbody.useGravity  = true;
                m_Rigidbody.angularDrag = m_AngularDrag;
                m_JumpState             = JumpStates.InAirDead;
                Debug.Log("Going to InAirDead!");
                break;

            case JumpStates.InAirAlive:
                MoveInAir(steer, forward, rollbrake);
                if ((Time.time - m_JumpTime) > m_SecondJumpTimer)
                {
                    // Time is up
                    m_JumpState = JumpStates.InAirDead;
                    Debug.Log("Going to InAirDead!");
                }
                else if (!m_JumpPressed && jump > 0f)
                {
                    m_JumpState = JumpStates.SecondJumpInit;
                    Debug.Log("Going to SecondJumpInit!");
                }
                GroundCheck();
                break;

            case JumpStates.InAirDead:
                MoveInAir(steer, forward, rollbrake);
                GroundCheck();
                break;
            }

            m_JumpPressed = (jump > 0f);
        }