// Use this for initialization
    // init() method has been created instead of Start() method to be able to
    // initialize the bullet when it is used again by a character
    virtual public void init(AttackLauncher _launcher, float _forceUp, float _forceForward)
    {
        m_launcher = _launcher;

//         if (_buttonToWatch.Contains("Cheat"))
//             fireCheat = true;
//         m_buttonToWatch = _buttonToWatch;
        m_risingStarted = false;
        m_risingDone    = false;
        m_flingDone     = false;
        m_isUnderground = true;

        if (launcher)
        {
            m_heightToReach = launcher.transform.position.y + m_size.y;
        }
        else if (m_launcher)
        {
            m_heightToReach = m_launcher.transform.position.y + m_size.y;
        }
        else
        {
            m_heightToReach = 1f + m_size.y;
        }

        m_forceUp      = _forceUp;
        m_forceForward = _forceForward;
    }
    public void fling(AttackLauncher _launcher, float _forceUp, float _forceForward, bool _heightReached)
    {
        m_launcher      = _launcher;
        m_risingDone    = _heightReached;
        m_risingStarted = _heightReached;
        m_flingDone     = false;
        m_forceUp       = _forceUp;
        m_forceForward  = _forceForward;
        Instantiate(m_smokeStartToMove, transform.position, Quaternion.identity);

        //updateSize();

        if (_heightReached || /*m_user.transform.position.y < transform.position.y &&*/ !isOnTheSameGroundOfTheUser())
        {
            m_heightToReach = transform.position.y;
        }
        else
        {
            m_heightToReach = transform.position.y + m_size.y;
        }

        if (m_previousPos.Count < 0)
        {
            m_previousPos.Add(transform.position);
            m_previousPos.Add(transform.position);
        }
    }
Пример #3
0
    private void basicAttack1()
    {
        AttackLauncher atkLauncher = GetComponent <AttackLauncher>();

        Ray        ray = atkLauncher.getAimRay();
        RaycastHit hit;
        bool       collided = Physics.Raycast(ray, out hit, 5000);

        BreakableRock breakableRock = null;

        if (hit.collider)
        {
            breakableRock = hit.collider.GetComponentInParent <BreakableRock>();
        }

        if (Physics.Raycast(ray, out hit, 5000))
        {
            if (collided && breakableRock != null)
            {
                breakableRock.breakRock(gameObject, GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward);
            }
            else
            {
                Collider[]    colliders = Physics.OverlapSphere(transform.position, m_rangeToTakeBullet);
                FlingableRock bullet    = null;

                if (colliders.Length > 0)
                {
                    bullet = findBullet(colliders);
                    if (!bullet)
                    {
                        spawnAndFlingBullet(GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward);
                    }
                    else
                    {
                        //                 GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                        //                 sphere.transform.position = transform.position;
                        //                 sphere.transform.localScale = new Vector3(1, 1, 1) * m_rangeToTakeBullet;
                        //                 sphere.GetComponent<SphereCollider>().enabled = false
                        //                UnityEditor.EditorApplication.isPaused = true;

                        bullet.setUser(gameObject);
                        myCurrentBullet = bullet;
                        bullet.fling(GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward, false);
                    }
                }
                else
                {
                    spawnAndFlingBullet(GetComponent <AttackLauncher>(), m_attack1ForceUp, m_attack1ForceForward);
                }
            }
        }
        GetComponent <BasicMovement>().m_Animator.Play("Attack 01");
        GetComponent <BasicMovement>().m_Animator.CrossFade("Grounded", 1f);
    }
Пример #4
0
    public void breakRock(GameObject _user, AttackLauncher _launcher, float _forceUp, float _forceForward)
    {
        if (transform.childCount <= 1)
        {
            return;
        }

        Transform child = transform.GetChild(0);

        if (!child.name.Contains("Part"))
        {
            return;
        }

        MeshRenderer childMeshRenderer = child.GetComponent <MeshRenderer>();

        float centerRatio = childMeshRenderer.bounds.size.y / (2 * m_size.y);

        m_boxCollider.center -= new Vector3(0, centerRatio, 0);

        float sizeRatio = 1 - childMeshRenderer.bounds.size.y / m_size.y;

        m_boxCollider.size = new Vector3(m_boxCollider.size.x, sizeRatio, m_boxCollider.size.z);

        m_size -= childMeshRenderer.bounds.size;

        if (m_pieceList.Count == 0)
        {
            return;
        }

        Object obj = Instantiate(m_pieceList[0], child.position + Vector3.up * 0.1f, child.rotation);

        m_pieceList.RemoveAt(0);

        GameObject gameObject = (GameObject)obj;

        scaleIt(gameObject);
        FlingableRock flingableRock = gameObject.GetComponent <FlingableRock>();

        Destroy(child.gameObject);
        flingableRock.setUser(_user);
        flingableRock.fling(_launcher, _forceUp, _forceForward, true);
    }
    void spawnAndFlingBullet(AttackLauncher _launcher, float _forceUp, float _forceForward)
    {
        Vector3    spawnProjectile = transform.position + transform.forward * m_OffsetForwardEarth;
        RaycastHit hit;

        if (Physics.Raycast(spawnProjectile, -Vector3.up, out hit, 50))
        {
            if (m_attack1Object.transform.childCount == 0)
            {
                return;
            }
            Transform    child        = m_attack1Object.transform.GetChild(0);
            MeshRenderer meshRenderer = child.GetComponent <MeshRenderer>();
            spawnProjectile = hit.point - new Vector3(0, meshRenderer.bounds.extents.y, 0);

            FlingableRock tmpBullet = ((GameObject)Instantiate(m_attack1Object, spawnProjectile, Quaternion.identity)).GetComponent <FlingableRock>();
            tmpBullet.setUser(gameObject);
            tmpBullet.init(_launcher, _forceUp, _forceForward);
        }
    }
    public void FixedUpdate()
    {
        if (m_pause)
        {
            return;
        }

        //        m_onControllerColliderHitAlreadyCalled = false;

        if (launcher == null)
        {
            launcher = GetComponent <AttackLauncher>();
        }
        if (launcher.isAnyBusy())
        {
            return;
        }

        Vector3 direction = transform.forward * m_forwardSpeed + transform.right * m_rightSpeed;

        direction.y = m_yVelocity;
        if (direction.z == 0 && direction.x == 0)
        {
            m_Animator.SetBool("Idle", true);
        }
        else
        {
            m_Animator.SetBool("Idle", false);
        }
        Vector3 newDir = transform.InverseTransformDirection(direction);

        m_Animator.SetFloat("Forward", newDir.z, 0.1f, Time.deltaTime);
        m_Animator.SetFloat("Turn", Mathf.Atan2(newDir.x, newDir.z), 0.1f, Time.deltaTime);
        m_Animator.SetFloat("Jump", m_yVelocity);

        float runCycle = Mathf.Repeat(m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime + 0.2f, 1);
        float jumpLeg  = (runCycle < 0.5f ? 1 : -1) * newDir.z;

        if (m_controller.isGrounded)
        {
            m_Animator.SetFloat("JumpLeg", jumpLeg);
        }

        if (m_controller.isGrounded && direction.magnitude > 0)
        {
            m_Animator.speed = 1f;
        }

        m_controller.Move(direction * Time.deltaTime);
        m_Animator.SetBool("OnGround", true);

        // --------------------------------------------Take a hit --------------------------------------------------
        if (!m_tookAHit)
        {
            return;
        }

        Vector3 speed = m_velocityHit;

        if (m_controller.isGrounded)
        {
            m_yVelocity     = 0;
            m_velocityHit.y = 0;
        }
        else
        {
            m_yVelocity -= m_gravity;
        }

        speed += Vector3.up * m_yVelocity;

        if (m_controller.isGrounded && m_speedFrictionHit != 0)
        {
            Vector3 friction = -speed.normalized * m_speedFrictionHit;
            if (Mathf.Sign(speed.x + friction.x) != Mathf.Sign(speed.x))
            {
                speed = Vector3.zero;
            }
            else
            {
                speed         += friction;
                m_velocityHit += friction;
            }
        }

        if (speed.magnitude < 1)
        {
            m_tookAHit = false;
        }

        m_controller.Move(speed * Time.fixedDeltaTime);
        // --------------------------------------------End take a hit --------------------------------------------------
    }