playMaker

Author Topic: Raycast: How to detect when raycast moves OFF an object?[SOLVED]  (Read 5701 times)

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Hello friends,

I am using a raycast to detect when it makes contact with a certain object type.

My question:
How can I use playmaker to determine when the raycast is no longer making contact with that object?

In the action, I see there's an event for Hit Event. I'd like something that is the equivalent to 'Hit Ended', if that makes sense.

Any suggestions?

Thanks!
« Last Edit: August 10, 2017, 03:00:45 AM by jeanfabre »

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Raycast: How to detect when raycast moves OFF an object?
« Reply #1 on: April 10, 2015, 04:17:12 AM »
You can use "Get Raycast hit info" to determine the hit object- store that object as a var and use a game object compare set to every frame-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Raycast: How to detect when raycast moves OFF an object?
« Reply #2 on: April 10, 2015, 03:03:31 PM »
Thanks for the suggestion, mdot!

I came up with a solution that suits my needs, and thought I'd share it here in case someone else is doing something similar:

Instead of a raycast, I created a really skinny, long box collider that extends 40 units out. Instead of tracking a ray cast hit, I'm using trigger enter/exit. Works perfectly for my purposes here.


mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Raycast: How to detect when raycast moves OFF an object?
« Reply #3 on: April 11, 2015, 12:35:04 AM »
Thats actually the same way I do my targeting system  :) Works really well too.
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

BenC

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Raycast: How to detect when raycast moves OFF an object?
« Reply #4 on: August 09, 2017, 07:24:01 PM »
Hey,

I was originally going to use a super long box collider as a child of the main camera. However I thought for an on trigger enter/exit I'd need to attach a rigid body to the box collider? But then that interferes when the camera hits other things in the scene that aren't triggers. Could you explain how you make the box collider register the trigger object without a rigid body?

EDIT: Ohh ok so all I needed to do was add a rigidbody to the object and then turn off gravity and tick 'is kinematic'. Awesome :)
« Last Edit: August 09, 2017, 07:31:14 PM by BenC »