Lasers stay on when I collide with something

Everything else seems to be working fine besides the lasers stay active after the player ship explodes. I am not entirely sure where in what script I would aim to fix that. I have searched Google and tried multiple things but I cant seem to figure it out. I can upload screenshots if needed. Thank you.

Hi @AAndrew,

Welcome to our community! :slight_smile:

Wjat exactly do you mean by lasers? The laser beams that have been shot before the player ship exploded? If so, that’s the desired behaviour because it’s like in the real world.

Screenshots would be great to help me understand the problem you would like to solve.

So what I mean is the lasers coming from the player ship will continue to be shot out after player ship is destroy by collision with another object, if the player dies while the “fire” button is being pressed otherwise they stay off. Seems like it disables control but locks it into the last position it was in at time of collision. How could I disable them from being active at the same time the player ship is destroyed? Its hard to show it in pictures, but I added some and I have added some screens of my scripts.






Thank you for your screenshots. Now I know what you mean, and I agree that this behaviour does not make any sense.

The problem is simple: The emission module gets enabled when the “fire” key was pressed. And if the player gets destroyed, the PlayerController gets disabled. The else-block in ProcessFiring will not get executed anymore.

An equally simple solution would be to have a SetLasersInactive method in the CollisionHandler method. A bunch of components get disabled there, just the lasers are missing.

If you want to challenge yourself, you could create a more elegant solution than copying and pasting the SetLasersActive method. You could outsource the shooting feature to a new class. Then you could make the CollisionHandler call a method in that new object to disable the lasers and to disable the component.

Maybe you’ll come up with an even better idea. :slight_smile:


See also: