Hi, I’m making a 3d game, if you guys play before “Phasmophobia”, you guys should know this kind of ghost will stop if you have light on him, in my game I have a very simple torch light (spot light), I wanted the ghost to stop when I have the torch light on him, sorry if I have bad English.
The simplest way is if you write a script and you SphereCast from the light source to the boundary of your light and see if any “enemy” is falling inside that cast. If something is hit, then you can decide what to do. Like you can “freeze” it (stop moving, stop animating or whatever you’re planning).
Thanks, I’ll try that, might need to learn more about SphereCast
Alternatively, if you don’t need that much control when the cast happens, you can use sphere collider as trigger. If you only need a “toggle” than you can use the OnTriggerEnter and OnTriggerExit (so you can freeze and unfreeze enemies) or you can use the OnTriggerStay to decide if you need to freeze the enemy per frame. Depending on how complicated your logic gets.
I don’t think its THAT complicated, I just can’t check if the object has the torch light’s “light” on it.
Any idea? ![]()
I would use a dotproduct test, very quick and more accurate than a sphere cast, but it doesnt handle things intersecting the beam
the torch throws out a cone of light
something like // 0.8 or whatever the angle of the torch is set to
if ( dot( (torchpos - ghostpos).normalized, directionoftorch.normalized ) > 0.8f )
{
ghost is in the light // though perhaps its behind a wall or something
}
I already give up my idea already, but still thanks a lot!