Free ActionScript

Flash AS2 & AS3 Tutorials, Game Code, Effects, Source Files & Sample Downloads

Laser Hitting Solid Objects & Walls

8 Comments »

As the title suggests, this is a laser weapon script that shoots a laser beam. The beam stops when it hits solid objects. Written in AS2 to be used in Flash shooter games.

Download Fla Sample

Download Fla Sample

If you’re having trouble understanding how this script works, please review previously posted examples that were incorporated in to this script: Shooting Laser Weapon & Apply Filters Dynamically.

Update:
ActionScript 3 version of this script is available here:

http://www.freeactionscript.com/2011/07/laser-weapon-with-wall-collision-detection/

8 Responses

epic.

im just a little confused about accuracy, when i change it, it doesnt change how close to the mouse it is shooting, but rather how far through the blocks it goes? or like sometimes the blocks dont stop them and othertimes it stops in the middle. you might want to make that a var you shouldnt change? or if you could explain your reasoning.

maybe a name like penetration or something would be better suited?

  • Hi imoncloudnine69,
    Yes, you are absolutely correct. It should be called penetration instead.

  • Thank you! I believe it was I who requested this. However, I don’t think I’ll be able to use this much. Checking every pixel on its path is pretty resource heavy, and if I have a big array of enemies that move, that might be too much. On the other hand, I could possibly give this to some boss.. hmm.

  • Hi jonathanasdf,
    Yes, the script IS pretty heavy, but there’s no way around that. You can tweak the accuracy (which should’ve been called penetration), so it doesn’ check every pixel.

    Also, you should not be doing a laser hit test on every enemy on the map. You need to start using broad phase/narrow phase collision detection.

  • Hey, maybe someone could try ( I know you’re busy ) the same script but with reflections off certain surfaces?

    I know that would be pretty hard, but it would be worth it…

  • hi am doing something similar in flash. i want to know how to make the laser bounce of a mirror? please help me.
    many thanks ^_^

  • Thanks very much pradvan ^_^

  • Leave a Reply

    You must be logged in to post a comment.