Example #1
0
    public List <Vector3> GetTrajectoryPoints(Vector3 startPoint, Vector3 endPoint, float time, Color color)
    {
        Vector3 initialVelocity  = TrajectoryMath.CalculateVelocity(startPoint, endPoint, time);
        float   deltaTime        = time / initialVelocity.magnitude;
        int     drawSteps        = (int)(initialVelocity.magnitude - 0.5f);
        Vector3 currentPosition  = startPoint;
        Vector3 previousPosition = currentPosition;

        Gizmos.color = color;

        List <Vector3> positions = new List <Vector3> {
            startPoint
        };

        if (IsParabolicVelocity(initialVelocity))
        {
            for (int i = 0; i < drawSteps; i++)
            {
                currentPosition += (initialVelocity * deltaTime) + (0.5f * Physics.gravity * deltaTime * deltaTime);
                initialVelocity += Physics.gravity * deltaTime;
                positions.Add(currentPosition);

                previousPosition = currentPosition;
            }
        }
        positions.Add(endPoint);
        return(positions);
    }
Example #2
0
 private void Update()
 {
     if (Input.GetMouseButton(0))
     {
         if (throwForce <= 1)
         {
             throwForce += 0.1f;
         }
     }
     else
     {
         if (throwForce > 0)
         {
             Animator anim = GetComponentInChildren <Animator>();
             if (anim.GetFloat("moveX") > 0)
             {
                 bombPos.localPosition = new Vector3(0.3f, 0.35f, 0);
             }
             else
             {
                 bombPos.localPosition = new Vector3(-0.3f, 0.35f, 0);
             }
             GameObject go = Instantiate(bombPrefab, bombPos.position, Quaternion.identity);
             go.GetComponent <Rigidbody2D>().velocity = TrajectoryMath.GetParableInitialVelocity(go.transform.position, Utility.GetMouseWorldPos(), throwForce);
         }
     }
     if (Input.GetMouseButtonUp(0))
     {
         throwForce = 0f;
     }
     UIManager.Instance.TrajectoryProgressBar(throwForce);
 }
Example #3
0
    public void Throw(string itemName, float reachtime)
    {
        GameObject objToThrow = null;


        if (itemName == "gold")
        {
            objToThrow = Instantiate(Gold, ThrowPoint.transform.position, new Quaternion());
        }
        else
        {
            foreach (var armor in _hero.Armor)
            {
                if (armor.name == itemName)
                {
                    objToThrow = Instantiate(armor, ThrowPoint.transform.position, new Quaternion());
                    break;
                }
            }
        }

        if (!objToThrow)
        {
            return;
        }

        objToThrow.SetActive(true);
        objToThrow.AddComponent <Rigidbody>();
        var throwable = objToThrow.AddComponent <Throwable>();

        throwable.SoundRadius           = SoundRadius;
        throwable.WaveParticuleLifeTime = WaveParticuleLifeTime;
        throwable.WaveParticuleEmiter   = WaveParticuleEmiter;
        objToThrow.GetComponent <Collider>().enabled = true;

        Vector3 velocity = TrajectoryMath.CalculateVelocity(objToThrow.GetComponent <Collider>().bounds.center, Target.transform.position, reachtime);

        var objectInterface = objToThrow.GetComponent(typeof(IPropelBehavior)) as IPropelBehavior;

        if (objectInterface != null)
        {
            objectInterface.React(velocity);
        }
    }