playMaker

Author Topic: Object hitted[SOLVED]  (Read 1621 times)

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Object hitted[SOLVED]
« on: August 31, 2017, 01:43:35 PM »
Hi,

raycasting forward from camera on a specific layer. Storing hit on a game object variable. It works, meaning that I get what has been hitted on the variable.

Now, what would be the best option to know that the hitted object knows he has been hitted?

Is there a "am i been hitted" action?

I know I can do it by a Get Name Action and then do a compare string to check if the object has been hitted but Ive been told comparing string is a really bad practice, specially if its every frame.

What would be the best practice here?

cheers

« Last Edit: September 04, 2017, 03:18:20 AM by jeanfabre »

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Re: Object hitted
« Reply #1 on: September 01, 2017, 02:57:05 PM »
Im really stuck on this.

I need to change the way I interact with objects from triggers to raycasting.

I have no way to know how to achieve "on exit" and "on stay".
Im trying now using raycast 2 with hit / no hit events trying to make a loop to simulate those behaviours but I cant make it work.

Not so much info in the forums.


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Object hitted
« Reply #2 on: September 02, 2017, 12:51:42 AM »
Hi, there is no action such as this. This is not a function of raycast. However, I might do it this way.

Raycast tells you which object it has hit. Save that object as a variable. When the ray hits a new object, send a global event to that object. Something like "On Global Enter". Make sure to setup this global variable on the object. (Any objects you want to be hit).

Then that object will know it has been hit.

Save that object variable to a second variable (so it doesnt get removed when you get to the next object). Use it to compare. Compare if object has changed. (If it is not the same anymore, then you know you have moved to the next object. Send the old object a global custom event for exit. Send the new object your on global enter). If it hasent changed, do nothing.

You can put those objects you want hit on a specific layer. So the ray cast will only hit those objects. That way, you dont send any extra un-necessary events to other objects that are not setup for it. (You can send events to them, but its just a waste).

Let me know if you understood that.

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Re: Object hitted
« Reply #3 on: September 02, 2017, 08:51:39 AM »
Dude!
DUDE!!

Thanks!!!!!