Пример #1
0
    /* The ship is always going fowards
     * Change the throttle of the ship with scroolwheel(Needs revision)
     * Rotate the ship in the y and x axis to change direction of the ship */
    void keyBoardMove()
    {
        float   z           = th.Cur;
        float   rotX        = 0;
        float   rotZ        = 0;
        float   changeSpeed = Input.GetAxis("Mouse ScrollWheel");
        Vector3 localVel    = transform.InverseTransformDirection(shCmps.Rb.velocity);

        if (changeSpeed > 0)
        {
            th.Increase();
        }
        else if (changeSpeed < 0)
        {
            th.Decrease();
        }
        if (th.Cur < 0 && localVel.z < 1)
        {
            z = 0;
        }


        if (Input.GetKey(KeyCode.W))
        {
            rotX += 40f;
        }
        if (Input.GetKey(KeyCode.S))
        {
            rotX = -40f;
        }
        if (Input.GetKey(KeyCode.A))
        {
            rotZ = 40f;
        }
        if (Input.GetKey(KeyCode.D))
        {
            rotZ = -40f;
        }

        shCmps.Rb.AddRelativeForce(new Vector3(0, 0.0f, z) * shCmps.Speed);

        Vector3    ROT           = new Vector3(rotX, 0.0f, rotZ);
        Quaternion deltaRotation = Quaternion.Euler(ROT * .05f);

        shCmps.Rb.MoveRotation(shCmps.Rb.rotation * deltaRotation);
    }
Пример #2
0
    /* Flight routine for a ship that has a target in sight(Needs revision) */
    void pursuitFlight()
    {
        float z = th.Cur;

        if (canSeeTarget())
        {
            th.Increase();
        }
        else
        {
            th.Decrease();
        }

        Vector3    toTarget       = targetEnemy.transform.position - transform.position;
        Quaternion targetRotation = Quaternion.LookRotation(toTarget);

        sharpness          = .015f - th.Cur * .0006f;
        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, sharpness);
        shComps.Rb.AddRelativeForce(new Vector3(0, 0.0f, z) * 10);
        attackDecision();
    }