예제 #1
0
    void DoFire()
    {
        if (myTarget == null)
        {
            return;
        }

        // Ignore vertical height for determining if we should shoot.
        Vector3 targetPos = myTarget.transform.position;

        targetPos.y = transform.position.y;

        if (Vector3.Angle(transform.forward, targetPos - transform.position) < targAngleCriteria)
        {
            // First, get our fire direction in local space
            Vector3 fireDir = Quaternion.Euler(-netChar.aimAngle, 0, 0) * new Vector3(0, 0, 1);

            // Add hand shake to make the bot less accurate

            //Vector3 innaccAngle = new Vector3( Random.Range(-targInnaccuracy, targInnaccuracy), Random.Range(-targInnaccuracy, targInnaccuracy), 0 );
            //fireDir = Quaternion.Euler(innaccAngle) * fireDir;

            //Debug.Log (fireDir);
            // Convert to global space
            fireDir = transform.TransformDirection(fireDir);

            netChar.FireWeapon(transform.position + transform.up * 1.5f, fireDir);
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        // WASD forward/back & left/right movement is stored in "direction"
        netChar.direction = transform.rotation * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        // This ensures that we don't move faster going diagonally
        if (netChar.direction.magnitude > 1f)
        {
            netChar.direction = netChar.direction.normalized;
        }


        // If we're on the ground and the player wants to jump, set
        // verticalVelocity to a positive number.
        // If you want double-jumping, you'll want some extra code
        // here instead of just checking "cc.isGrounded".
        if (Input.GetButton("Jump"))
        {
            netChar.isJumping = true;
        }
        else
        {
            netChar.isJumping = false;
        }

        AdjustAimAngle();

        if (Input.GetButton("Fire1"))
        {
            // Player wants to shoot...so. Shoot.
            netChar.FireWeapon(Camera.main.transform.position, Camera.main.transform.forward);
        }
    }
예제 #3
0
    void DoFire()
    {
        if (myTarget == null)
        {
            return;
        }

        Vector3 targetPos = myTarget.transform.position;

        targetPos.y = transform.position.y;
        if (Vector3.Angle(transform.forward, targetPos - transform.position) < targetAngleCriteria)
        {
            Debug.Log("aa: " + -netChar.aimAngle);
            Quaternion aa = Quaternion.Euler(-netChar.aimAngle + Random.Range(-targetInaccuracy, targetInaccuracy), 0, 0);
            Debug.Log("ai: " + aa.eulerAngles);
            Vector3 fireDir = aa * Vector3.forward;
            //Debug.Log("ac " + fireDir);
            //Vector3 inacc = new Vector3(Random.Range(-targetInaccuracy, targetInaccuracy),
            //                            Random.Range(-targetInaccuracy, targetInaccuracy), 0);
            //fireDir = Quaternion.Euler(inacc) * fireDir;
            //Debug.Log("ia " + fireDir);
            fireDir = transform.TransformDirection(fireDir);
            Debug.Log("ws " + fireDir);

            netChar.FireWeapon(transform.position + new Vector3(0f, 1.5f, 0f), fireDir);
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        // forward/back & left/right movement is stored in "direction"
        netChar.direction = transform.rotation * new Vector3(Input.GetAxis("Horizontal"), 0,
                                                             Input.GetAxis("Vertical"));
        if (netChar.direction.magnitude > 1.0f)
        {
            netChar.direction = netChar.direction.normalized;
        }

        // handle jumping
        netChar.isJumping = (Input.GetButton("Jump"));

        if (Input.GetButton("Fire1"))
        {
            netChar.FireWeapon(Camera.main.transform.position, Camera.main.transform.forward);
        }

        AdjustAimAngle();
    }