Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Rabagast on August 18, 2016, 02:48:23 AM

Title: Creating a laser
Post by: Rabagast on August 18, 2016, 02:48:23 AM
Hi!
I have tried so many times now to get this to work properly. And I'm very close.
I try to create a laser beam. And everything works except one thing. When the laser hits a wall, the laser particle will stop, but the laser collider will go through the wall and hit the enemy on the other side. I tried to disable the hit enemy FSM when the laser hits the wall. Well, it works. It didn't kill the enemy on the other side, but then it will be a problem if I have an enemy on the player side next to the wall. The laser doesn't kill that either.

So my question is:
What is the best way to set up a collider for a laser beam?
I saw in another topic that Raytracer would be good for this. But I don't find any Raytracer. What is Raytracer? Can anybody help me?
Thanks! :)
Title: Re: Creating a laser
Post by: ... on August 18, 2016, 03:00:09 AM
It's raycasting. Are you working in 2D or 3D? Can you explain us a bit more how you laser works?
Title: Re: Creating a laser
Post by: Rabagast on August 18, 2016, 03:36:43 AM
Hi!
Thanks for the answer!

It will be in 2.5D. I show you a video. There you can see the problem.

As in the video, the laser beam is left and right only. The laser is creating from a prefab and destroy itself when I release the fire button.
I just wonder what is the best way to setup up a collider so the laser beam doesn't go through the walls and kill the enemies on the other side.

https://www.youtube.com/watch?v=d59IkXGKBLw (https://www.youtube.com/watch?v=d59IkXGKBLw)

Title: Re: Creating a laser
Post by: ... on August 18, 2016, 03:59:08 AM
Hi,

thanks for the video, chek out these two videos please :)

https://www.youtube.com/watch?annotation_id=annotation_86234213&feature=iv&src_vid=ST4ZXiRqTlg&v=hUg3UfE186Q

Laser is constantly turned on in the video, but you can tweak that easily by yourself.
Title: Re: Creating a laser
Post by: Rabagast on August 18, 2016, 04:17:57 AM
Hi!
Thanks for the video! :)

Does this laser hits something behind the obstacles even if the laser stop? Because that is the problem I have.
Title: Re: Creating a laser
Post by: ... on August 18, 2016, 08:54:00 AM
No it doesn't, i didn't understand you well. So you need the laser to stop at the wall but still hit something behind it? Do you need it to be seen after the obstacle?
Title: Re: Creating a laser
Post by: Rabagast on August 19, 2016, 04:54:51 AM
No! I don't want it to hit anything behind the wall. My laser stop at the wall, but the laser collider go through the wall and hit the enemy behind it. I use 3D Box Collider.
Title: Re: Creating a laser
Post by: djaydino on August 19, 2016, 06:55:00 AM
Hi,
Maybe it is better to use raycasting and use layers?
Title: Re: Creating a laser
Post by: Rabagast on August 21, 2016, 05:04:54 AM
Hi,
Maybe it is better to use raycasting and use layers?

Yes, you are right. It was better to use Raycast, but the raycast also go through walls and hit the enemy on the other side, I solved this with another Raycast which disable the FSM which hits the enemy, but then it will not hit the enemy on the players side either if you know what I mean. Of course, maybe I don't need to have enemies like this, so close to a wall. At least not on the players side, but I also want to find a solution for this.

Another thing I can try is to use a Particle Collider Script I got here. :-)
http://hutonggames.com/playmakerforum/index.php?topic=2682.0 (http://hutonggames.com/playmakerforum/index.php?topic=2682.0)
Title: Re: Creating a laser
Post by: djaydino on August 21, 2016, 09:00:54 AM
Hi,
The raycast should not go through the wall unless your ray cast surpassed the center of the wall (collider)
Maybe your weapon (raycast) moves inside the wall
Title: Re: Creating a laser
Post by: Rabagast on August 21, 2016, 11:10:43 AM
On the laser, I have the Raycast. And when I walk close to the wall, the Raycast will be visible on the other side of the wall. I don't understand what do you mean and how a Raycast should not go through a collider.
Title: Re: Creating a laser
Post by: djaydino on August 21, 2016, 06:07:21 PM
Hi,
I have been testing a bit and
Actually when the raycast enters a collider it will not see it any more (not in the center)

Yes you can see the raycast on debug, but it will only register the 1st object hit
(unless you are using layer mask)
There is also a custom action (raycast 2) that can also do something when nothing is hit, that might be useful.

A solution might be to adjust your player collider so that the raycast can't go against the wall, or move the raycast a bit deeper in the gun.
Title: Re: Creating a laser
Post by: Rabagast on August 22, 2016, 05:22:51 AM
I'm using layer mask on the raycast. Of course when the raycast hits something it goes to a new state, and then the raycast will disappear. But in this case, it only goes to a new state only when the raycast hits an enemy.

I will check out Raycast 2.

I show you another video from the scene view, so you can see how it is. :)

https://www.youtube.com/watch?v=aieZU-mCKvg (https://www.youtube.com/watch?v=aieZU-mCKvg)
Title: Re: Creating a laser
Post by: djaydino on August 22, 2016, 06:07:07 AM
Hi,
That is indeed not what you want to happen,
The problem might be on how you have setup your actions/states

I can check it out if you want.
You can pm me a link to your project or you can make repo of this part in a new project and send that to me.

Btw i am almost everyday on discord (chat application)
Title: Re: Creating a laser
Post by: Rabagast on August 22, 2016, 06:36:57 AM
Yes, that would be great. :)
I can send you a pm on Discord later when I have it ready.
I need to recreate it in a brand new project. It's better. :)
Title: Re: Creating a laser
Post by: ... on September 22, 2016, 08:52:07 AM
I don't want to open another topic, so i'll post in this if it's not a problem.

I'm havin difficulties in making a laser. Hit detection with raycasting 2d is not a problem, but i'm struggling with the cosmetic part of it.

I am using a draw line custom action from the ecosystem, and all i need for it is to stop when it collides with the enemy. Any ideas on how to accomplish this?