playMaker

Author Topic: [SOLVED]raycasting a piercing shot  (Read 2726 times)

johanesnw

  • Playmaker Newbie
  • *
  • Posts: 26
[SOLVED]raycasting a piercing shot
« on: January 18, 2014, 02:01:12 PM »
I'm adding a sniper character to my WIP game (2d tower def. the camera perspective is like Plants vs Zombies) and wanna make the sniper shot pierces all enemies in range.
So I create a raycast to the end of the screen, and after it destroy the 1st target, it will loop to the raycast state and check the ray again to the end of the screen, and stops when there's no object colliding with the ray anymore.
when I test it with 5 objects, it works fine. but somehow I forgot to add HP, and when I added it.... as you can guess, it keeps damaging the 1st object till it dies.
is there any better way to make a piercing shot / laser gun shot?
or should I create a looooong invisible object upon firing and checks every colliding object?
I'm new to unity and PM, so maybe there are lots of easier to use methods that I don't know  :)



EDIT: finally get this to work. After the raycast hit an object it will  check whether there's an enemy behind it or not.
if Yes, then the shooted object will be the sniper that cast a ray behind it, and check again if theres an enemy behind target.
and of course I have to set the "shooted" variable to the sniper everytime it goes to idle state. :)
« Last Edit: January 19, 2014, 05:36:52 AM by johanesnw »

LogLady

  • Full Member
  • ***
  • Posts: 150
Re: [SOLVED]raycasting a piercing shot
« Reply #1 on: August 26, 2015, 03:12:02 PM »
Thanks for coming back and sharing this solution. Helped me a lot!