playMaker

Author Topic: most efficient way to fire a laser beam  (Read 4095 times)

santelia

  • Junior Playmaker
  • **
  • Posts: 78
most efficient way to fire a laser beam
« on: June 19, 2012, 01:04:41 PM »
Hi mates, I need many suggestions on how to correctly fire a laser beam from the player to a target.
In my RPG project I'm currently using a WOW camera targeted on the player (a droid).
Let's say that on a certain key pressed (cmd) the cursor becomes a target.
And from then you can click and get the object hit if any.
So, what can you suggest on how to fire a laser beam with an efficient process?
Guess the theps could be:
1) get the position property of the player transform component and put it in variable POS;
2) get the rotation property of the player transform component and put it in variable ROT;
3) set an origin for the laser beam (could be somewhere beyond the player, either on its capsule surface), making some math with the POS;
BUT THEN...?
What would you suggest for properly setting the target point?
And for best drawing a laser line (hopefully without need of vectrosity)?
Maybe I can switch from a laser beam to a vector effect (there are some decent on the store), but the main question still remains...
« Last Edit: June 19, 2012, 01:07:37 PM by santelia »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: most efficient way to fire a laser beam
« Reply #1 on: June 19, 2012, 02:46:48 PM »
I'm not going into detail, but do you know about raytrace? It would allow you to get the distance to the hit object. Then apply that to a cube which is by default 1 units long, rotate it until it faces the direction of the ray and then scale it on the axis which is 1 unit long by the distance value. Make sure the origin of the cube is in the middle of the face facing your player.
Then you can create a shader which doesn't rely on UV's but on screenspace or worldspace and there you go, a perfect laser!

PS: If it's too complex I can create it for you tomorrow, but right now I'm just too tired, sry ;D
« Last Edit: June 19, 2012, 02:51:31 PM by kiriri »
Best,
Sven

santelia

  • Junior Playmaker
  • **
  • Posts: 78
Re: most efficient way to fire a laser beam
« Reply #2 on: June 20, 2012, 03:07:44 AM »
Hi Kiriri, thanks for the tip. Yes I know about raytrace, but never used till now. How much is it cpu intensive? Wouldn't fit a Mouse Pick action too? Of course would be great, to say the less, if you could help. Thank you mate.
« Last Edit: June 20, 2012, 09:24:36 AM by santelia »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: most efficient way to fire a laser beam
« Reply #3 on: June 20, 2012, 11:19:52 AM »
a raytrace is the very most basis of collisions. Everything which is collision based, including the mouse pick action and internally even the collision actions relys heavily on raytrace. So there's no worries if you're running hundreds of rays at the same time. Actually, if you want to get into AI, you simply WILL run hundreds of them at the same time ;D
I'll create a laser for you in a min.
« Last Edit: June 20, 2012, 11:22:38 AM by kiriri »
Best,
Sven

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: most efficient way to fire a laser beam
« Reply #4 on: June 20, 2012, 12:08:19 PM »
www.twisted-pantheon.com/Downloads/New%20Unity%20Project%205.7z
use the most recent playmaker.dll on it, then load it as a normal project.
This is really by far the most cost efficient choice, as no matter what you do, you will have to 1) calculate the laser distance and 2) draw the laser. This fsm does that and nothing else.

I didn't create the laser shader for you, as that takes a lot of experimenting, but I can give you tips if you need any :)
Best,
Sven

santelia

  • Junior Playmaker
  • **
  • Posts: 78
Re: most efficient way to fire a laser beam
« Reply #5 on: June 20, 2012, 12:16:24 PM »
Thank you so much Kiriri. I have to admit that I'm completely unfamiliar with shader creation. So any tip is absolutely welcome!