Exemplo n.º 1
0
    /*
     * algo from: https://gamedevelopment.tutsplus.com/tutorials/adding-turbulence-to-a-particle-system--gamedev-13332
     */
    private Vector3 applyVortex(Vector3 pos, VortexType type)
    {
        float distanceX = float.MaxValue;
        float distanceY = float.MaxValue;
        float distanceZ = float.MaxValue;
        float distance  = float.MaxValue;

        Vector3 direction = Vector3.zero;

        foreach (GameObject a in Attractors)
        {
            if (Vector3.Distance(pos, a.transform.position) < distance)
            {
                distanceX = (pos.x - a.transform.position.x);
                distanceY = (pos.y - a.transform.position.y);
                distanceZ = (pos.z - a.transform.position.z);
                distance  = Vector3.Distance(pos, a.transform.position);
            }

            direction += (a.transform.position - pos).normalized;
        }

        float vortexScale = 10f;
        float vortexSpeed = 5f;

        Vector3 distances = new Vector3(distanceX, distanceY, distanceZ);

        Vector3 totalForce;

        switch (type)
        {
        case VortexType.Forward:
            totalForce = vortexForward(vortexSpeed, 20f, distances, direction);
            break;

        case VortexType.Up:
            totalForce = vortexUp(vortexSpeed, vortexScale, distances, direction);
            break;

        case VortexType.UpRepulsion:
            totalForce = vortexUpRepulsion(vortexSpeed, vortexScale, distances, direction);
            break;

        case VortexType.ForwardRepulsion:
            totalForce = vortexForwardRepulsion(vortexSpeed, 15f, distances, direction);
            break;

        default:
            totalForce = vortexForward(vortexSpeed, vortexScale, distances, direction);
            break;
        }
        return(totalForce);
    }
Exemplo n.º 2
0
 public Vector3 ApplyVortexSpecial(VortexType type, Vector3 position)
 {
     return(applyVortex(position, type));
 }