public static void Create(Vector3 fromPosition, Vector3 targetPosition)
    {
        Vector3  shootDir            = (targetPosition - fromPosition).normalized;
        float    distance            = Vector3.Distance(fromPosition, targetPosition);
        float    shootAngle          = GetAngleFromVectorFloat(shootDir);
        Vector3  spawnTracerPosition = fromPosition + shootDir * distance * .5f;
        Material tracerMaterial      = new Material(GameAssets.i.m_WeaponTracer);

        tracerMaterial.SetTextureScale("_MainTex", new Vector2(1f, distance / 256f));
        World_Mesh worldMesh = new World_Mesh(null, spawnTracerPosition, new Vector3(1, 1), shootAngle - 90, 6f, distance, tracerMaterial, null, 10000);

        int frame     = 0;
        int frameBase = 0;

        worldMesh.SetUVCoords(new World_Mesh.UVCoords(16 * frame + 64 * frameBase, 0, 16, 256));
        float framerate = .016f;
        float timer     = framerate;

        FunctionUpdater.Create(delegate {
            timer -= Time.deltaTime;
            if (timer < 0)
            {
                timer += framerate;
                frame++;
                if (frame >= 4)
                {
                    worldMesh.DestroySelf();
                    return(true);
                }
                worldMesh.AddPosition(shootDir * 2f);
                worldMesh.SetUVCoords(new World_Mesh.UVCoords(16 * frame + 64 * frameBase, 0, 16, 256));
            }
            return(false);
        });
    }
    private void CreateWeaponTracer(Vector3 fromPosition, Vector3 targetPosition)
    {
        Vector3  dir                     = (targetPosition - fromPosition).normalized;
        float    eulerZ                  = UtilsClass.GetAngleFromVectorFloat(dir) - 90;
        float    distance                = Vector3.Distance(fromPosition, targetPosition);
        Vector3  tracerSpawnPosition     = fromPosition + dir * distance * .5f;
        Material tmpWeaponTracerMaterial = new Material(weaponTracerMaterial);

        tmpWeaponTracerMaterial.SetTextureScale("_MainTex", new Vector2(1f, distance / 256f));
        World_Mesh worldMesh = World_Mesh.Create(tracerSpawnPosition, eulerZ, 6f, distance, tmpWeaponTracerMaterial, null, 10000);

        int   frame     = 0;
        float framerate = .016f;
        float timer     = framerate;

        worldMesh.SetUVCoords(new World_Mesh.UVCoords(0, 0, 16, 256));
        FunctionUpdater.Create(() => {
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                frame++;
                timer += framerate;
                if (frame >= 4)
                {
                    worldMesh.DestroySelf();
                    return(true);
                }
                else
                {
                    worldMesh.SetUVCoords(new World_Mesh.UVCoords(16 * frame, 0, 16, 256));
                }
            }
            return(false);
        });
    }
Beispiel #3
0
    private void WeaponTracer(Vector3 fromPosition, Vector3 targetPosition)
    {
        float distanceOffset = 0.3f;

        Vector3 dir = (targetPosition - fromPosition).normalized;

        float eulerZ   = Utilities.GetAngleFromVectorFloat(dir) - 90f;
        float distance = Vector3.Distance(fromPosition, targetPosition);

        distance = distance + distanceOffset;
        Vector3 tracerSpawnPosition = fromPosition + dir * distance * 0.5f;

        Material tmpWeaponTracerMaterial = new Material(weaponTracerMaterial);

        tmpWeaponTracerMaterial.SetTextureScale("_MainTex", new Vector2(1f, (distance / 190f)));

        World_Mesh worldMesh = World_Mesh.Create(tracerSpawnPosition, eulerZ, .2f, distance, weaponTracerMaterial, null, 10000);

        float timer = 0.1f;

        FunctionUpdater.Create(() =>
        {
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                worldMesh.DestroySelf();
                return(true);
            }
            return(false);
        });
    }
Beispiel #4
0
    //creates a mesh to visually represent the raycast
    //then deletes the mesh after a few seconds
    private static void BulletTracer(Vector3 t_startPoint, Vector3 t_endPoint)
    {
        Vector3 direction = (t_endPoint - t_startPoint).normalized;

        Material tracer = (Material)Resources.Load("Textures/BulletTracer");

        float eulerZ = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - 90;

        float distance = Vector3.Distance(t_startPoint, t_endPoint);

        Vector3 tracerSpawnPos = t_startPoint + direction * 0.5f;

        World_Mesh bulletMesh = World_Mesh.Create(tracerSpawnPos, eulerZ, 0f, distance, tracer, null, 10000);

        float timer = 0.1f;

        FunctionUpdater.Create(() =>
        {
            timer -= Time.deltaTime;

            if (timer <= 0)
            {
                bulletMesh.DestroySelf();
                return(true);
            }
            return(false);
        });
    }
Beispiel #5
0
    private void CreateWeaponTracer(Vector3 fromPosition, Vector3 targetPosition)
    {//If we want to restrict the angle of fire we can add a check for it here
        float    distance            = Vector3.Distance(fromPosition, targetPosition);
        Vector3  dir                 = (targetPosition - fromPosition).normalized;
        Vector3  tracerSpawnPosition = fromPosition + dir * distance * .5f;
        float    zRot                = GetAngleFromVectorFloat(dir) - 90;
        Material tmp                 = new Material(projectile);

        tmp.SetTextureScale("_MainTex", new Vector2(1f, distance / 600f));
        World_Mesh   worldMesh = World_Mesh.Create(tracerSpawnPosition, zRot, .5f, distance, projectile, null, 10000);
        float        timer     = .1f;
        LayerMask    mask      = LayerMask.GetMask("Default");
        RaycastHit2D hit       = Physics2D.Raycast(tracerSpawnPosition, dir, 10f, mask);

        Debug.DrawRay(tracerSpawnPosition, targetPosition, Color.red);
        if (hit.collider != null)
        {
            Debug.Log("hit" + hit.transform.position);
            GameObject hitObject = hit.transform.gameObject;
            if (hitObject.GetComponent <ReactiveTarget>())
            {
                Debug.Log("saw enemy");
                hitObject.GetComponent <ReactiveTarget>().ReactToHit();
                _scoreController.AddScore(3);
            }
        }
        FunctionUpdater.Create(() =>
        {
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                worldMesh.DestroySelf();
                return(true);
            }

            return(false);
        });
    }