Script runs on windows, fails on mac

Hi there,

I’m having an issue with a block of code not behaving on a mac as it does on windows machines. The issue occurs on the mac in the editor, in a standalone build and in the webplayer.

After some debugging I’ve found this section to be the culprit. It works perfectly on windows yet fails to return true on a mac.

bool Check(Vector3 Player, Vector3 Me)
	{

		if(Player.x >= Me.x - Mathf.Epsilon   Player.x <= Me.x + Mathf.Epsilon)
		{
			
			if(Player.y >= Me.y - Mathf.Epsilon   Player.y <= Me.y + Mathf.Epsilon)
			{
				
				if(Player.z >= Me.z - Mathf.Epsilon   Player.z <= Me.z + Mathf.Epsilon)
					return true;
				
				
				else return false;
			}
			else return false;
		}
		else return false;
		
	}

Any help would be greatly appreciated.

In this code is nothing platform specific, can you describe the behavior you encountered on both windows and mac, also which behavior the correct one should be?

Maybe the Mathf.Epsilon value is different on each platform, but I doubt it. Is there maybe other code we can look at?

Asside from any possible errors, that code could be written a lot shorter and easier if you compare the Vector3.Distance between the positions.

Something like:

if(Vector3.Distance(Player, Me) < 0.1f)
{
      return true;
}

Interesting. This is comparing rotation but I guess that’s another idea I hadn’t thought of. There are no errors appearing anywhere as far as I can see.

I’m aware it’s not platform specific (hence why my brain hurts trying to figure out the issue). I’ve checked each axis individually and on the mac at least one of them is not returning true as it does on windows. The game runs perfectly besides this function.

I’ve sent off to the support team to hopefully get some more insight. Worse comes to worse I’ll try other solutions such as that Fluzing suggested. I’m open to trying any other methods, was using Mathf.Epsilon simply because I wanted to give it a go.

Thanks for the suggestion Fluzing! That’s working great :smile:. Won’t be trying anything fancy for a while.

You’re welcome.

Less is often better :slight_smile:

OMG Thumbs up to this! Programming is very zen. The more I master it, the simpler my code gets. :wink: