Issue w/ checking if object is in front/behind of an object

Hi,

I’m using this code to check if an object is in front of another, and when the player moves in front of the object the 1st time it reads “facing target”, but then after that there is no output, even if I go behind the object. This is in a method that is called every frame from the Update() function.

if (transform.InverseTransformPoint(Player.position).z > 0)
	{
		Debug.Log("facing target!");

	}
	else
	{
		Debug.Log("Not facing target!");

	}
}

Thanks!

That code can’t complete without printing one of two messages to the console. If you aren’t seeing any messages, the code isn’t executing. If you aren’t getting any errors then you probably have a bug in your logic that prevents control ever reaching this code.

I put in a counter to make sure that it was going more than one, sure enough it is. The issue could be with the checking code…

function checkFacing()
{
Debug.Log(“enter check facing” + counter);
//Debug.Log(Player.position.z);
counter++;

Still can’t figure out why this isn’t working. :frowning:

Turn off “collapse” in the console.

–Eric

Ah! Eric, you’re practically a professional problem fixer. That did the trick.

Thanks!