Problem with shooting in 2D platformer course 17 (?)

Updated on February 18, 2016 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on February 15, 2016

Going through number 17 in the 2D platfomer course, I realized that the bullet trail when I shoot only renders when I hit an object. For example, if I’m shooting towards a platform and hit it, the bullet trail will render, but if I’m just shooting out into space, I won’t be able to see the trail.

Has anyone ran into this problem and/or know how to solve it? Any thoughts appreciated 🙂

  • Liked by
1 on February 15, 2016

Well, I haven’t followed the series so could you post the part of the script that renders the trail?

on February 18, 2016

This function controls the shooting graphics: 

 void Effect (Vector3 hitPos, Vector3 hitNormal)
 Transform trail = Instantiate (BulletTrailPrefab, firePoint.position, firePoint.rotation) as Transform;
 LineRenderer lr = trail.GetComponent<LineRenderer>();
 if (lr != null)
 lr.SetPosition(0, firePoint.position);
 lr.SetPosition(1, hitPos);
 Destroy(trail.gameObject, 0.04f);
 if (hitNormal != new Vector3 (9999, 9999, 9999))
 Transform hitParticle = Instantiate(hitPrefab, hitPos, Quaternion.FromToRotation(Vector3.right, hitNormal)) as Transform; //adjust rotation by 'Vector3.[direction]
 Destroy(hitParticle.gameObject, 1f);
 Transform clone = (Transform) Instantiate (MuzzleFlashPrefab, firePoint.position, firePoint.rotation);
 clone.parent = firePoint;
 float size = Random.Range (0.6f, 0.9f);
 clone.localScale = new Vector3 (size, size, size);
 Destroy (clone.gameObject, 0.02f);
 //Shake the camera
 camShake.Shake(camShakeAmount, camShakeLength);
Show more replies
  • Liked by