playMaker

Author Topic: Creating a laser  (Read 5795 times)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Creating a laser
« 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! :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Creating a laser
« Reply #1 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?
Available for Playmaker work

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #2 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

Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Creating a laser
« Reply #3 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.
Available for Playmaker work

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #4 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.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Creating a laser
« Reply #5 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?
Available for Playmaker work

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #6 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.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Creating a laser
« Reply #7 on: August 19, 2016, 06:55:00 AM »
Hi,
Maybe it is better to use raycasting and use layers?

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #8 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
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Creating a laser
« Reply #9 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

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #10 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.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Creating a laser
« Reply #11 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.

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #12 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
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Creating a laser
« Reply #13 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)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Creating a laser
« Reply #14 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. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no