playMaker

Author Topic: FPS Raycasting to Highlight/Unhighlight Objects [SOLVED]  (Read 5688 times)

marka87uk

  • Playmaker Newbie
  • *
  • Posts: 4
FPS Raycasting to Highlight/Unhighlight Objects [SOLVED]
« on: June 25, 2014, 06:56:38 PM »
Hi, I wish to use raycasting in order to highlight game objects which are deemed 'interactive'. I have created a layer which all of my interactive objects are in, and I have a raycast working from the FPS camera, however, it seems to be stuck in a loop of highlighting/unhighlighting the object every single frame, possibly due to the raycast hitting the background behind the object.

I wonder if you can see where I may be going wrong? :)

Thanks! 8)
« Last Edit: June 26, 2014, 06:52:44 PM by Alex Chouls »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: FPS Raycasting to Highlight/Unhighlight Objects
« Reply #1 on: June 25, 2014, 07:20:20 PM »
Why do you need to raycast to the background?

I've done something similar. I raycast on an interactive layer, when I hit something I store it, then change the color of the stored object just as you're doing but..

I gave each button an FSM and global event for when it is hovered. When the raycast connects then it stores the gameobject, but I send the event from a Game Object Changed action instead of the raycast so it loops back into the raycast and waits for the connecting object to change then sends the hover event to it when it does.

Might be worth trying something similar. The downside is having an fsm and event for mouseover on each individual button but that does also convey a lot of flexibility as well, rather than just saying whatever the ray hits will change material color.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

marka87uk

  • Playmaker Newbie
  • *
  • Posts: 4
Re: FPS Raycasting to Highlight/Unhighlight Objects
« Reply #2 on: June 26, 2014, 03:08:07 AM »
It was just a method I thought of to turning off the highlighting, but I am happy to try other/better ideas!

I'm very new to Unity and Playmaker still - is there any chance you could elaborate a bit on what I'd need to do? :)

marka87uk

  • Playmaker Newbie
  • *
  • Posts: 4
Re: FPS Raycasting to Highlight/Unhighlight Objects
« Reply #3 on: June 26, 2014, 12:44:24 PM »
OK, thank you for your advice earlier; I'm getting there but doing it in a slightly different way...

The raycast on the camera now just stores the hit object in a global variable as you suggested.

On the crate (the highlightable object) I have an 'object compare' action to see if it is the same as the hit object. If it is, highlight it, if it's not, then unhighlight it.

It kind of works but the problem is the ray is quite short because I only want highlighting to occur if the player is near the object, however this means that when the player moves away, the hit object doesn't change (and therefore doesn't unhighlight) until the time that another object is hit.

Any ideas or does my logic still need to change? :)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: FPS Raycasting to Highlight/Unhighlight Objects
« Reply #4 on: June 26, 2014, 01:20:48 PM »
I think I fixed that by modifying the action to store the data even if it didn't hit anything, making the gameobject change to null... I think.. I'll have to look at it when i get home.

I also have a variable for lastTouched, so when i store the new gameObject for highlighting I can go ahead and store it, jump to the highlighting state, send a message to highlight the lastTouched object, then send an event to the newTouched gameobject... Might be confusing, but I basically needed to maintain a difference in two variables, the one thats turning on and the one thats turning off.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

marka87uk

  • Playmaker Newbie
  • *
  • Posts: 4
Re: FPS Raycasting to Highlight/Unhighlight Objects
« Reply #5 on: June 26, 2014, 03:29:29 PM »
Got it, thank you!

All what was needed was an action after highlighting the object to set the hit object variable back to null. :)

fuzzywobs

  • Playmaker Newbie
  • *
  • Posts: 25
Re: FPS Raycasting to Highlight/Unhighlight Objects
« Reply #6 on: May 13, 2015, 02:28:48 PM »
Why do you need to raycast to the background?

I've done something similar. I raycast on an interactive layer, when I hit something I store it, then change the color of the stored object just as you're doing but..

I gave each button an FSM and global event for when it is hovered. When the raycast connects then it stores the gameobject, but I send the event from a Game Object Changed action instead of the raycast so it loops back into the raycast and waits for the connecting object to change then sends the hover event to it when it does.

Might be worth trying something similar. The downside is having an fsm and event for mouseover on each individual button but that does also convey a lot of flexibility as well, rather than just saying whatever the ray hits will change material color.

Lane (or anyone!), could you expand in more detail how you did this? I'm not sure I fully understand global variables and how to get it working.

Thanks!

Edit:

I managed to figure out how to use the global event and used the method you suggested Lane. I can now highlight and unhighlight to my hearts content.

The next step is not working though. What I've tried adding is if the game object is highlighted, AND you click space bar, the character contoller 1 is deactivated, and the character controller 2 is activated. However, in the editor it just seems to deactivate the character controller 1 without activating the character controller 2. While testing it out in the oculus rift, once i hit spacebar on the highlighted object, the game just freezes or hangs on the last highlighted view. The game itself doesnt actually crash, but the camera view is frozen. Any ideas?
« Last Edit: May 13, 2015, 05:43:46 PM by fuzzywobs »