playMaker

Author Topic: Raycast logic mind-melt [SOLVED]  (Read 367 times)

curb47

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Raycast logic mind-melt
« Reply #15 on: February 19, 2021, 04:44:21 AM »
Yes, I have a pooler system set up, prefabs etc. I didn't think about 'pre-fabing' and pooling the Draw Line, it makes sense.

I could then, after the raycast, spawn a Draw Line and set the start/end?

RAVEN001

  • Junior Playmaker
  • **
  • Posts: 58
    • View Profile
Re: Raycast logic mind-melt
« Reply #16 on: February 19, 2021, 05:00:52 AM »
Globals are your best friend, Find actions are what is bad (find closest is inefficient because it needs to send a raycast to ALL objects to find the closest, find child (or is it get child, dunno.) is inefficient because it has to search ALL child objects to find the child you want. If you give a direct target from a tag, or a global variable it's the most direct path to the object you are referencing.

Use globals.

with your problem, try adding the line draw to the damage event, DON'T add the raycast. It should still take the last point it was given and continue drawing the line. Otherwise, seperate the draw line from the damage fsm completely. i.e have an fsm that ONLY controls the line draw, based on hit (again add tag compare to this fsm)
« Last Edit: February 19, 2021, 05:23:01 AM by RAVEN001 »

RAVEN001

  • Junior Playmaker
  • **
  • Posts: 58
    • View Profile
Re: Raycast logic mind-melt
« Reply #17 on: February 19, 2021, 06:19:08 AM »
do you have a testing device? i.e you are talking a lot about efficiency so your deployment is mobile? Testing in the editor DOES NOT indicate how it will work on a mobile device. Build and test on a device regularly. Camera distance, shaders, shadows, load times, there  are a lot of of reasons to test on a device, i'd recommend at least a 1080 screen device, cos lets face it 2k display is now the standard, 4k is primo and 8k is samsungs new standard. My point is, editor plays DON'T represent how the game will actually play on a device.

curb47

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Raycast logic mind-melt
« Reply #18 on: February 23, 2021, 02:19:54 AM »

with your problem, try adding the line draw to the damage event, DON'T add the raycast. It should still take the last point it was given and continue drawing the line. Otherwise, seperate the draw line from the damage fsm completely. i.e have an fsm that ONLY controls the line draw, based on hit (again add tag compare to this fsm)

The but I need the raycast to be continuous because that defines the hit point/end point of the draw line. If there's no raycast, the line doesn't move as the Titan rotates to find the player spaceship. Know what I mean?

The draw line needs the 'every frame' updated position of the raycast hit point.

If I were to turn the Titan laser fire into a pulse fire weapon I can do that, no problem, that's how I've done the player spaceship lasers, but I'm trying to add variation to my enemies, and having the continuous 'hosepipe' laser is really what I'm after.

curb47

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Raycast logic mind-melt
« Reply #19 on: February 23, 2021, 02:20:36 AM »
I'm really struggling with this. It's kinda doing my head in.

curb47

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Raycast logic mind-melt
« Reply #20 on: February 23, 2021, 03:14:22 AM »
Maybe I actually need to have 2 raycasts on separate FSMs for each laser? One to drive the Draw Line, with no events or anything, and one to handle the hit detection which can trigger damage etc.

I'm under the impression that raycast is expensive, so maybe it's not the best solution, but I can't think of any other way.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5822
    • View Profile
    • jinxtergames
Re: Raycast logic mind-melt
« Reply #21 on: February 23, 2021, 07:19:43 AM »
Hi.
You could maybe store the object hit and use a 'Fsm Game Object Compare (Tag)' on a 'damage handler' fsm.
and/or user 'Store Did Hit' and use a 'Fsm Bool Test' on the 'damage handler' fsm.

on the 'damage handler' fsm you can set a delay :

State 1 check raycast fsm (Fsm Game Object Compare (Tag)/Fsm Bool Test)
State 2 Do damage
State 3 Delay (for example wait 0.1)
Go back to state 1

curb47

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Raycast logic mind-melt
« Reply #22 on: February 23, 2021, 08:51:41 AM »
Hello,

Thanks, I'm at work right now so will need to re-address this later, or tomorrow morning.

curb47

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: Raycast logic mind-melt
« Reply #23 on: February 24, 2021, 04:15:53 AM »
Hi,

So, this is what I've ended up with, and it works pretty well...



The global event 'Fire' is activated when the Titan is in range of the player.

1. Spawn Laser, spawns a pooled Prefab of the Laser which has the Draw Line action, and two child objects for the Start & End of the Draw Line.

2. Main Raycast spits out the raycast, and sets the position (every frame) of the End object in the laser/Draw Line prefab. It also stores any hit objects and has a Game Object Tag Switch, one for the player and one for other enemies. If nothing is Hit after a Wait of 3, it goes to FINISHED which sends an event to stop firing lasers/De-spawn the pooled Laser/Draw Line prefab and start the Titan hunting again.

If the player is hit by the raycast, it goes to the hitPlayer event which zips through the Subtract Player Health state which simply sends a global event to the player spaceship to reduce health by 1 (int), and then on to Aux Raycast. I did not want to use a global variable for Health because I've worked really hard at completely stripping my game of global variables.

3. Aux Raycast is a copy of Main Raycast, but with no Tag Switch for the player spaceship and is mainly used to continue driving the Draw Line laser prefab. It has a Wait of 0.3 then FINISHED.

4. Clear Hit Object sets the hit object variable stored in Main Raycast to Null, so it doesn't instantly send the hitPlayer event.

The result is pretty much perfect. If the player is hit by the laser, it takes 1 off Health, and an additional 1 off Health for every Wait 0.3 the player is in the path of the laser. It's cool, because there are loads of other enemies doing different things, and sometimes it's not a case of simply flying out of the path of the lasers, so things get quite hectic and exciting!

I'll mark the thread as SOLVED. I've done plenty of game testing and it seems really solid.

Thanks.
« Last Edit: February 24, 2021, 04:31:59 AM by curb47 »