Beispiel #1
0
 void Awake()
 {
     controller = GetComponent <TrickController> ();
 }
Beispiel #2
0
    /**
     * get all input from player related to controlling behavior on the ground
     * author: kurtdog
     * */
    public void GroundInput()
    {
        //Debug.Log("GroundInput");
        airTime = 0;         // we're on the ground so reset the airTime timer;

        /**
         * axis is float, 1 to -1. This way we can have multiple inputs.
         * the axis is referenced from the point of the joystick
         **/
        waypoint = getClosestWaypoint();
        //Debug.Log("waypoint: " + waypoint.gameObject.name);
        float verticalAxis = 1;        //Input.GetAxis("Vertical");

        //float horizontalAxis = //Input.GetAxis("Horizontal");

        // when on the ground, update these vars, they're sent to air input to calculate torque for spins and flips
        //horizontalAxisAtJump = horizontalAxis;
        //verticalAxisAtJump = verticalAxis;

        controlledSpeed = maxSpeed * verticalAxis;

        // if crouched
        if (Input.GetButton("Jump"))
        {
            // no transform.rotate
            loadTorque();                       // start loading torque
            controlledSpeed = currentSpeed + 5; // the speed before we crouched + a small boost will equal our crouch speed
            //rigidbody.transform.Rotate(0,crouchedTurnSpeed*horizontalAxis,0); // rotate on the horizontal axis, left and right
        }
        // otherwise
        else
        {
            // move normally
            //rotate in the direciton of the waypoint
            //Vector3 waypointForward = new Vector3(0,waypoint.transform.eulerAngles.y,0);
            Vector3 AIForward = new Vector3(0, this.transform.eulerAngles.y, 0);


            float angle = waypoint.transform.eulerAngles.y - this.transform.eulerAngles.y;
            //Debug.Log("Angle: " + angle);
            Vector3 rotation = Vector3.Lerp(new Vector3(0, 0, 0), new Vector3(0, angle, 0), 1f * Time.deltaTime);
            this.transform.Rotate(rotation);
            currentSpeed = controlledSpeed;             // when on the ground, update and keep track of "currentSpeed"
        }


        // if Key is Released
        if (Input.GetButtonUp("Jump"))       // if pressing jump key
        {
            //Debug.Log("Jumping");
            rigidbody.AddForce(new Vector3(0, jumpForce, 0));
            loadXTime = 0;
            loadYTime = 0;
        }

        // reset button
        //Debug.Log ("UP:" + this.transform.up);
        //Debug.Log ("difference: "+ (this.transform.localRotation.x - defaultOrientation.x));

        xRot += TrickController.deltaFlipRotation(this.transform.rotation.eulerAngles.x, lastFlipRotation);
        Debug.Log("Xrot: " + xRot);
        lastFlipRotation = this.transform.rotation.eulerAngles.x;
        if (xRot > 180)        //we should update this to refer to a global reset button (not just for PC)
        {
            Debug.Log("RESET");
            //rigidbody.transform.rotation = new Vector3(rigidbody.transform.rotation.x,defaultOrientation.y,rigidbody.transform.rotation.z);
            rigidbody.transform.rotation = defaultOrientation;
            xRot = 0;
        }

        // speed up and slow down
        // adds a force in the x direction, "verticalAxis" ranges from -1 to 1 depending on player joystick input.
        //Vector3 controlledSpeed = (this.transform.forward)*verticalAxis;


        //Vector3 forwardForce = (this.transform.forward)*speed;
        //rigidbody.transform.position += forwardForce * Time.deltaTime;
    }