The Laser Problem

Vaibhav Sangwan

  • Posts: 161
Hi there,
I want to create a laser beam. The laser beam will start from a laser creator and remain until a tile comes in its path.
Because of performance issues, I can't use small actors making up path of laser beam.
I also can't use only on one actor for laser path as distances for different cases will be different.
I can't use Image API too. Because code will become much complex and I am not much familiar with Image API. Although I have seen Abigayl's tutorial.


Any ideas?
What should I do?
Thanks for your help in advance.
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated

Bombini

  • *
  • Posts: 1385
Hm...you are exlcuding a lot already.
Raycast would work of course.

Cheers

Vaibhav Sangwan

  • Posts: 161
Thanks Bombini for replying
ummm...Raycast??
I'm gonna try it and tell you all if it works.
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated

Vaibhav Sangwan

  • Posts: 161
All right, so the collisions worked just how I wanted them to be.
Thanks Bombini.
But...
What about sprites and animations?
How would I make them?
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated

Bombini

  • *
  • Posts: 1385
Well there is only drawing left i guess if you cant use actors...
I always use actors for lasers.

Vaibhav Sangwan

  • Posts: 161
Then how you specify how long they will be?
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated

Bombini

  • *
  • Posts: 1385
For actors: I just add them to the direction i want untill the hit a tile or whatever.
For drawing....hm...good question. I havent touched raycast for a long time unfortunately.

Vaibhav Sangwan

  • Posts: 161
I think that the code will be very complicated. Because I want laser to look good(not just a single red line). I will make it so that its opacity decreases ,will add some effects too. So I'll try to make it work in a day or two and get back here.
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated

TheIndieStation

  • *
  • Posts: 2263
Is simple. If you have the start position and the position where your raycast hits a tile, you can simply draw a line between those 2 points. No image API required, just  single draw line block.

merrak

  • *
  • Posts: 2644
If you have the ... position where your raycast hits a tile...

Just to add a quick comment on this: Unless something changed with the raycast extension, I don't recall that being a simple thing to calculate. You don't want to use the (x,y) location returned by the raycast, since that won't give you the position of the tile. It'll give you the position of the merged block of tiles.

Instead, you want to loop through the list of collided actors/terrain and find the one with the lowest "fraction" parameter. This will be the first object hit. To compute the (x,y) location of the hit, use

x = x1 + t * ( x2 - x1 )          y = y1 + t * ( y2 - y1 )

where t is the fraction, (x1,y1) is the location of the gun, and (x2,y2) is the other coordinate you pass to raycast. Once you have (x,y), then draw a line from (x1,y1) to (x,y)

Vaibhav Sangwan

  • Posts: 161
Thank you Indie station and merrak for your replies.

@IndieStation
I'm gonna need these lasers many times. Also, I  will have to draw these  and its ssurrounding lines.
They all will have some behaviors.
So, simply raycasting will not be so efficient.
I will make a behavior for it.


@Merrak
I think that it solved much part of my problem.I will try it after I return home
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated

Vaibhav Sangwan

  • Posts: 161
Thank you all for your answers, I think that I made it playble( maybe I can call  it fine looking).
Cheers...
Currently working on:-
http://www.stencyl.com/game/play/42376
Feedback will be really appreciated