Max Range of Projectile

Just starting out and I would like to modify the behavior of a projectile in one of the tutorial examples.

In my case it’s a simple laser, but once it’s fired… it just exists forever and flies off into space.

I would like to set a max range for projectiles and just have them terminate when they reach it.

Seems relatively simple, not exactly sure where to begin? I was contemplating treating each projectile as if it had “fuel” of some sort and when it runs out the object is destroyed. Another thought was a radius or sphere at the origination point and terminate when it reaches the end?

Wondering how you all may have handled this?

I have a general script I tack on, usually call it TTL, or TimeToLive… it counts up in time and destroys the GameObject it is located on when the time is exceeded. It’s so trivial I just usually write it each time, but you’re welcome to take this one;

https://bitbucket.org/kurtdekker/proximity_buttons/src/2beb3a4fa0d31bb670c57be564cb4d0fcd16c3a5/proximity_buttons/Assets/DemoTwinStickShooter/TTL.cs

You can either put it in your prefab, or else add it with code using the static .Attach() method.

1 Like