コード例 #1
0
    /*
     * This method is what controls the side sweeping motion
     * While the key is held down, your vehicle banks and moves in
     * that direction.
     * After they are down banking, the vehicle rights itself
     * Speed is a constant associated with a type of vehicle
     * Correction is how much the player wants to move sideways
     * Previous steer what the player inputed last frame.
     * turning makes sure the player is not turning while banking
     *
     */

    protected void MoveHorizontal(float speed, float correction, float previousSteer, bool turning)
    {
        if (StateManager.curState == 3)
        {
            //make sure we only detect landscape
            int layerMask = 1 << 9;
            //left side of vehicle
            RaycastHit lhit;
            //right side of vehicle
            RaycastHit rhit;
            //Getting the ground
            Physics.Raycast(transform.position + 2 * transform.right, Vector3.down, out rhit, Mathf.Infinity, layerMask);
            Physics.Raycast(transform.position + -2 * transform.right, Vector3.down, out lhit, Mathf.Infinity, layerMask);
            //if we turning right
            if (correction > .8 && !turning)
            {
                Rb.AddForceAtPosition(transform.up * 1 / rhit.distance, transform.position + 2 * transform.right);
                Rb.AddForceAtPosition(transform.up * 1 / lhit.distance * 300, transform.position + -2 * transform.right);
                Rb.AddForce(transform.right * speed * correction * 20);
                //left
            }
            else if (correction < -.8)
            {
                Rb.AddForceAtPosition(transform.up * 1 / rhit.distance * 300, transform.position + 2 * transform.right);
                Rb.AddForceAtPosition(transform.up * 1 / lhit.distance, transform.position + -2 * transform.right);
                Rb.AddForce(transform.right * speed * correction * 20);
                //must bring balance to the forces
            }
            else
            {
                Rb.AddForceAtPosition(transform.up * 1 / rhit.distance * 15, transform.position + 2 * transform.right);
                Rb.AddForceAtPosition(transform.up * 1 / lhit.distance * 15, transform.position + -2 * transform.right);
            }
        }
    }
コード例 #2
0
    protected override void OnTriggerEnter(Collider col)
    {
        if (col.CompareTag("LevelEdge"))
        {
            gameObject.SetActive(false);
            ReturnToPool();
            EventManager.TriggerEvent("Damage", null);
        }

        if (col.CompareTag("Stick"))
        {
            if (IsOnStick)
            {
                return;
            }

            _target = col.transform;
            Invoke("NewParent", 0.2f);
            IsOnStick      = true;
            Rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;
            var pointContact = Collider.ClosestPoint(col.transform.position);
            var direction    = col.transform.TransformPoint(col.bounds.size) - col.transform.position;
            direction = new Vector3(direction.x, 0, 0);
            Rb.AddForceAtPosition(direction * PowerInpuls, pointContact, ForceMode.Impulse);
        }
    }
コード例 #3
0
    protected override void OnTriggerEnter(Collider col)
    {
        base.OnTriggerEnter(col);

        if (col.CompareTag("Stick"))
        {
            if (IsOnStick)
            {
                return;
            }

            ManagerSound.Instance.PlayEffect(Track.FruitSplash);
            var pointContact = Collider.ClosestPoint(col.transform.position);
            var angelContact = col.GetComponent <DataObject>().RotationZ + 180f;

            var particle = PoolManager.GetObject(PoolType.Particles).GetComponent <ParticleSystem>();
            particle.gameObject.SetTransform(pointContact, Quaternion.Euler(0, 0, angelContact), col.transform);
            particle.GetComponent <ParticleSystemRenderer>().material = ColorParticle.Colors[(int)TypFruit];
            particle.Play();

            IsOnStick      = true;
            Rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY |
                             RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY |
                             RigidbodyConstraints.FreezeRotationX;
            var direction = col.transform.TransformPoint(col.bounds.size) - col.transform.position;
            direction = new Vector3(direction.x, 0, 0);
            Rb.AddForceAtPosition(direction * _powerImpuls, pointContact, ForceMode.Impulse);
            Collider.enabled = false;
        }
    }
コード例 #4
0
    // Update is called once per frame
    new void Update()
    {
        base.Update();
        MoveZDir(speed, 1);
        //This ensures they can only collide with landscape layer
        int layerMask = 1 << 9;
        //The Raycast hit for the front "Thruster"
        RaycastHit fhit;

        //Casting rays to get ground information
        Physics.Raycast(transform.position, Vector3.down, out fhit, Mathf.Infinity, layerMask);

        //Adding our own gravity
        Rb.AddForceAtPosition(Vector3.up * -5 * Mathf.Min(fhit.distance, 270), transform.position);
        //Adding thrust upward
        Rb.AddForceAtPosition(transform.up * (7500 / fhit.distance), transform.position);
        //Adding a dampening force
        Rb.AddForceAtPosition(Vector3.up * -2.5f * Rb.velocity.y, transform.transform.position);
    }
コード例 #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!wallHit)
        {
            wallCooldown -= Time.deltaTime;
        }
        if (wallCooldown < 0)
        {
            wallHit      = true;
            wallCooldown = 1f;
        }

        if (Health <= 0)
        {
            healthBar[0].SetActive(false);
            healthBar[1].SetActive(false);
            healthBar[2].SetActive(false);
            healthBar[3].SetActive(false);
            healthBar[4].SetActive(false);
            healthBar[5].SetActive(false);

            if (!ended)
            {
                gm.EndGame();
                ended = true;
            }
        }
        else if (Health < startingHealth && Health > 5 * startingHealth / 6)
        {
            temp = 1 / 6;
        }
        else if (Health <= startingHealth * 5 / 6 && Health > 2 * startingHealth / 3)
        {
            healthBar[0].SetActive(false);
        }
        else if (Health <= (startingHealth * 2) / 3 && Health > startingHealth / 2)
        {
            healthBar[0].SetActive(false);
            healthBar[1].SetActive(false);
        }
        else if (Health <= startingHealth / 2 && Health > startingHealth / 3)
        {
            healthBar[0].SetActive(false);
            healthBar[1].SetActive(false);
            healthBar[2].SetActive(false);
        }
        else if (Health <= startingHealth / 3 && Health > startingHealth / 6)
        {
            healthBar[0].SetActive(false);
            healthBar[1].SetActive(false);
            healthBar[2].SetActive(false);
            healthBar[3].SetActive(false);
        }
        else if (Health <= startingHealth / 6 && Health > 0)
        {
            healthBar[0].SetActive(false);
            healthBar[1].SetActive(false);
            healthBar[2].SetActive(false);
            healthBar[3].SetActive(false);
            healthBar[4].SetActive(false);
        }
        base.Update();          //making sure we do Vehicle update
        if (speedTimer <= 0)    //if speed power up has ended
        {
            speed           = 20.0f;
            dampeningFactor = -2.5f;
            hoverHeight     = 2000f;
        }
        else
        {
            speedTimer -= Time.deltaTime;             //else decrease timer
        }
        if (slowTimer <= 0)
        { //if slow effect has ended
            speed           = 20.0f;
            dampeningFactor = -2.5f;
            hoverHeight     = 2000f;
        }
        else
        {
            slowTimer -= Time.deltaTime; //else decrease timer
        }
        if (inverseTimer <= 0)
        { //if inverseTrap has ended
            inverseTrap = 1;
        }
        else
        {
            inverseTimer -= Time.deltaTime; //else decrease timer
        }
        //This ensures they can only collide with landscape layer
        int layerMask = 1 << 9;
        //The Raycast hit for the front "Thruster"
        RaycastHit fhit;
        //The Raycast hit for the back "Thruster"
        RaycastHit bhit;

        //Casting rays to get ground information
        Physics.Raycast(transform.position + transform.forward * 5, Vector3.down, out fhit, Mathf.Infinity, layerMask);
        Physics.Raycast(transform.position - transform.forward * 5, Vector3.down, out bhit, Mathf.Infinity, layerMask);
        //Adding our own gravity
        Rb.AddForceAtPosition(Vector3.up * -5 * Mathf.Min(fhit.distance, 30), transform.position);
        //Adding thrust upward
        Rb.AddForceAtPosition(transform.up * (hoverHeight / fhit.distance), transform.position + transform.forward * 5);
        Rb.AddForceAtPosition(transform.up * (hoverHeight / bhit.distance), transform.position - transform.forward * 5);
        //Adding a dampening force
        Rb.AddForceAtPosition(Vector3.up * dampeningFactor * Rb.velocity.y, transform.transform.position);
        previousSteer = correction;         //getting the previous correction for use in the method
        if (gm.Xbox_One_Controller)         //if were using a xbox controller
        {
            if (Input.GetAxis("Drive") > .9)
            { //left stick Up/Down
                throttle = 1;
            }
            else if (Input.GetAxis("Drive") < -.9)
            {
                throttle = -1;
            }
            else
            {
                throttle = 0;
            }

            if (Input.GetKey(KeyCode.JoystickButton14) || Input.GetKey(KeyCode.JoystickButton5))
            {
                correction = 1;
            }
            else if (Input.GetKey(KeyCode.JoystickButton13) || Input.GetKey(KeyCode.JoystickButton4))
            {
                correction = -1;
            }
            else
            {
                correction = 0;
            }

            if (Input.GetAxis("Turn") > .9)
            {
                turn = 1;
            }
            else if (Input.GetAxis("Turn") < -.9)
            {
                turn = -1;
            }
            else
            {
                turn = 0;
            }
            if (Input.GetKey(KeyCode.JoystickButton7) || Input.GetKey(KeyCode.Joystick1Button9))
            {
                gm.Pause();
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.W))
            {
                throttle = 1;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                throttle = -1;
            }
            if (Input.GetKey(KeyCode.Q))
            {
                correction = -1;
            }
            else if (Input.GetKey(KeyCode.E))
            {
                correction = 1;
            }

            if (Input.GetKey(KeyCode.A))
            {
                turn = -1;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                turn = 1;
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                gm.Pause();
            }
        }
        //useful in two spots, here and to make sure we're allowed to bank
        turning = Mathf.Abs(turn) > .1;
        if (turning)
        {
            TurnRotate(turn, speed);
        }
        //move forward
        MoveZDir(speed, throttle);
        //bank sideways
        MoveHorizontal(speed, correction, previousSteer, turning);
        //reset everything for next fram
        throttle   = 0;
        correction = 0;
        turn       = 0;
    }
コード例 #6
0
    new void Update()
    {
        if (base.Health <= 0)
        {
            deathSound.Play();
            Death();
        }
        MoveZDir(speed, 1);
        //This ensures they can only collide with landscape layer
        int layerMask = 1 << 9;
        //The Raycast hit for the front "Thruster"
        RaycastHit fhit;

        //Casting rays to get ground information
        Physics.Raycast(transform.position, Vector3.down, out fhit, Mathf.Infinity, layerMask);

        //Adding our own gravity
        Rb.AddForceAtPosition(Vector3.up * -5 * Mathf.Min(fhit.distance, 270), transform.position);
        //Adding thrust upward
        Rb.AddForceAtPosition(transform.up * (5000 / fhit.distance), transform.position);
        //Adding a dampening force
        Rb.AddForceAtPosition(Vector3.up * -2.5f * Rb.velocity.y, transform.transform.position);
        transform.LookAt(vehicle);

        Vector3   fwd        = transform.TransformDirection(Vector3.forward);
        Vector3   bwd        = transform.TransformDirection(Vector3.back);
        Vector3   lwd        = transform.TransformDirection(Vector3.left);
        Vector3   rwd        = transform.TransformDirection(Vector3.right);
        Rigidbody rrb        = base.Rb;
        int       layerMask2 = 1 << 8;

        layerMask2 = ~layerMask2;
        if (Vector3.Distance(transform.position, vehicle.position) >= MinDist)
        {
            //transform.position += transform.forward * MoveSpeed * Time.deltaTime;
            //this.MoveZDir(MoveSpeed, 1);



            if (Vector3.Distance(transform.position, vehicle.position) <= MaxDist)
            {
                //Shoot at here or something
            }

            if (Physics.Raycast(transform.position, fwd, detectDist, layerMask2))
            {
                rrb.AddForce(transform.right * speed * -2500 * Time.deltaTime);
            }
            else if (Physics.Raycast(transform.position, bwd, detectDist, layerMask2))
            {
                rrb.AddForce(transform.forward * speed * 2500 * Time.deltaTime);
            }
            else if (Physics.Raycast(transform.position, lwd, detectDist, layerMask2))
            {
                rrb.AddForce(transform.forward * speed * 2500 * Time.deltaTime);
            }
            else if (Physics.Raycast(transform.position, rwd, detectDist, layerMask2))
            {
                rrb.AddForce(transform.right * speed * -2500 * Time.deltaTime);
            }
            else
            {
                this.MoveZDir(MoveSpeed, 1);
            }
        }
    }