Making a laser

0 favourites
  • 15 posts
From the Asset Store
Make your own platformer for both the web and mobile easy with this Santas Platformer Template, FULLY DOCUMENTED
  • Hi guys!

    I'm trying to get this laser set-up I have going here working properly.

    Laser Example

    The objects are draggable, so you can see how it behaves.

    The problem is the laser is penetrating into both the obstacle and the target. I know WHY it's doing that, as I have it set to target the X and Y of each object...but I don't know how else to do it =

    Anyone able to clue me in on a better way?

    On a side note: Can anyone explain to me why this extremely simple capx is 36 mbs? -_-

  • Sorry could you explain further what you would like the laser to do or not do?

  • Yeah that would help wouldn't it? :P Sorry, must have gotten distracted by some technical issues I was having with Dropbox.

    What I would like to have happen with the laser is for it to collide with the OUTSIDES of the obstacle and target sprites, instead of it going inside them they way it does now.

    Like I said though, I can only get it to target the centers.

  • Here's how I usually like to go about lasers. You can play with those values to change the maximum range and precision.

    It's a good idea to change the 'obstacle' object reference into a family reference (e.g. 'LaserBlocking' so you can have multiple objects block the laser, but I wasn't sure if you had the free edition).

    I have no idea why it was over 30mb, that was really weird. I saved it as a project folder, then saved that as a capx, and that fixed it. Very odd.

  • I think it's to do with bbox. Something like (laser.x,laser.y,target.bboxright,target.bboxbottom) will have it stop on the right side of the object. I guess mess about with the bbox thing a bit as setting it to bboxright will only work when laser is on the right of the object and setting it to bboxleft will only work when laser is on the left of the object. Decent starting point though..

  • Oh wow, sqiddster. You got it to go around the edges of the circle and everything. Very nice :)

    So close >.< The only issue now is to get the laser to stop at the outside of the target as well, instead of going all the way through it. Or at the very least for it to hit the center like it did before. I'd be happy with that too, I could just hide that with layers.

  • You have a 26MB folder called 'Sai 1.1.0 + brushes' inside that capx. Plus a shortcut to Photoshop among other things :) I guess everything in the project folder gets put into the capx when you do save as single file?

  • Wow what the hell? lol

    No idea how that happened at all. I saved it to the desktop once as a project file though by accident. That must have been it. Weird though, I didn't place any of my desktop items inside it O.o

    Anyway squiddster's version is far superior, so I'll just delete the old one.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Before you do too much math to get it to stop short, wouldn't it be easier to set the z-order and have the laser behind the obstacles? It would look like it hit the side.

  • I thought of that and even played with that idea before. And while that works, the laser (now) goes through the target object and out the other side of it, so it looks a little weird. If it stopped at it's center your idea would be perfect :)

    The laser beam has to "collide" with the obstacle sprite though. There's no getting around that in my particular game. =\</p>

  • Change the Set laser width in the Else event (#5) to

    min(self.Width + self.increment,distance(laser.X,laser.Y,target.X,target.Y))

  • Gosh Paradox, I could hug you right now...thanks so, so much! :D

    I only know a few expressions so far. distance, angle etc. I never saw that one. I'll remember it for any future use.

    Really, thanks everyone for your help. That was a problem that's been at me for a while now. I never would have figured that out if it weren't for all your help.

  • Kazan to make it hit the target as well, all you have to do is add a family - instead of checking for collision with the 'obstacle', check for collision with the family. Then, just add the obstacle AND the target to that family.

  • sqiddster

    Yeah I meant to say thank you for the family idea as well. I haven't given those a lot of attention yet. That will make this and a lot of other things a heck of a lot easier.

    Thanks again :)

  • No problem, glad I could help!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)