playMaker

Author Topic: crosshair question in VR - raycast actions?  (Read 1252 times)

stain2319

  • Playmaker Newbie
  • *
  • Posts: 9
crosshair question in VR - raycast actions?
« on: April 10, 2020, 06:41:03 PM »
Hoping someone can help me with the logic/actions side of it.  I get what I'm "supposed" to do but I can't seem to make it work as expected.

The basic situation is:

- I have a VR camera rig which follows the player's head
- I attached a child object to the camera, offset by about +30Z
- on this object I put a sprite renderer with a crosshair sprite

I am essentially trying to change the color of the crosshair to red when it's over an enemy (as determined by raycasting forward from the sprite itself) and then as soon as it's no longer over the enemy it goes back to green.

I tried various Raycast options and was able to make it raycast and even record the object hit in a variable so I could tell my raycast is working, but I can't seem to figure out the logic behind how to make it raycast every frame and change the sprite color based on the result.  It kinda seems like it either only raycasts once (even though I have it set to do so every frame) or it raycasts until it hits, then does stuff, but then doesn't go back to raycasting... and either way it never moves on to changing the color.


If anyone has a good workflow for this I would be very appreciative.  I feel like I must be missing something simple in terms of how to test the raycast and change the result based on hit/no hit.