playMaker

Author Topic: Detecting raycast hitting collider  (Read 4469 times)

Mulbin

  • Junior Playmaker
  • **
  • Posts: 90
Detecting raycast hitting collider
« on: August 04, 2017, 02:48:59 PM »
Hi all,

Could anyone tell me how to use playmaker to detect a raycast hitting a collider?  I have a raycastr on a moving object and I need to know when the ray passes through a collider on another object.

At present I am using Gameflow instead of Playmaker for just this one function... would be nice to use Playmaker for everything! - Gameflow has a simple function called "detect raycast"

spektron

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Detecting raycast hitting collider
« Reply #1 on: August 06, 2017, 04:43:51 PM »
Hello,
the action raycast can store the hit object and have an OnHitEvent.
you may notify the collided object like that.

seems trivial and maybe I've not understood you...
if you meant the object the ray pass thru while colliding with another, then
I'd have another ray for all layers unlike the first ray to check for hit, but this way you would still get just the first pass thru object...

Mulbin

  • Junior Playmaker
  • **
  • Posts: 90
Re: Detecting raycast hitting collider
« Reply #2 on: August 07, 2017, 07:59:53 PM »
hmm, that's a shame, would need a full rebuild of how my game works to do it that way.

With GameFlow (another program like playmaker), you attach a script to any object which then detects when that object has been hit by the ray, and triggers an event. - very simple.

With playmaker (if I understand) the raycaster detects when it has hits something, then stores the value, then you have to use that value to tell the object it's been hit, so you can then trigger the event?.  - overly complicated.

I'll keep using gameflow for this function I think, don't fancy re-scripting 200 objects ;)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Detecting raycast hitting collider
« Reply #3 on: August 07, 2017, 08:53:45 PM »
Hi,
There are 2 actions that actions that can be useful, raycast and raycast all

raycast will get the 1st object it hits and raycast all will get all the objects it hits.

But you do not need to get the object, you can also set a bool and/or only send a event.

if you want only to trigger certain object, you can use layer masks, for example :

i have 3 enemies (red, blue, yellow) on layer (top left in inspector) i add a layer for each enemy.
On the raycast action i set layer mask to 2 and then i add red and blue.

when i play the game it will only register red and blue now.

Quote
overly complicated.
I don't think it is overly complicated, it just works diferently.
But as i understand...you have 200 objects raycasting??

You can btw copy/paste an fsm or use templates.
« Last Edit: August 07, 2017, 09:01:24 PM by djaydino »

Mulbin

  • Junior Playmaker
  • **
  • Posts: 90
Re: Detecting raycast hitting collider
« Reply #4 on: August 08, 2017, 06:12:05 PM »
No, I only have 1 object raycasting (the camera).  I have 200 objects that need to know when the ray is hitting them. 200 layers isn't really an option.

I'll stick with GameFlow, like I said it has a very simple "detect ray" script that lets the object detect when a ray is hitting it.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Detecting raycast hitting collider
« Reply #5 on: August 08, 2017, 08:28:48 PM »
Hi,
I an not saying you have to change  :),
but as you said you want to use playmaker for it i am trying to say it is not that hard. it is just a different way.

And from what i understand with gameflow, you have a "detect ray" on each object (200 scripts)?
If so i don't think that this is a optimal way doing something like that.

What are you doing with the object when you hit it?

A common way using the ray cast action is,

start raycast :
When it hits an object, store it in a variable,
next state :
(for example) Destroy the selected object.

so only 1 FSM (script) and 2 actions are needed to do this.

The layer part is to detect only certain layers.

You can use that part in 2 ways, include layer or exclude layers.
To exclude layers you need check invert layer mask.

So for example you can make a 'player' layer and a 'floor' layer, place them in the raycast and check invert layer mask.

For your objects you do not need 200 layers probably, you just need 1 layer 'enemies' (for example)