position of objects, as a function of the direction of a transformation.

I have two objects and I need to determine which of the two objects is further ahead of the direction my player is facing (which is a third transformation). to do this I thought of calculating the Z axis of each object trying not to use the global Z axis of each object but converting the global Z axis into that of the player

 If (player.TransformDirection (Target1.position) .z <player.TransformDirection (Target2.position) .z)
print ("ok");
[/ codice]

Unfortunately it doesn't work, or at least only when the player is facing in certain directions, consequently I think I have the wrong meaning of transformDirection. I would like to understand the right method to know which of the 2 targets is ahead, always considering the player's z axis and not the global one.

TransformDirection only cares about, well, the direction that a vector is pointing; not how big it is, or where it’s located in absolute terms. It’s for transforming concepts like “northward” or “upward”. You want to transform a point rather than a direction.

Also, TransformDirection converts from local space to world space. You’re trying to convert from world space to local space.

So the function you want is InverseTransformPoint

so to know if target1 is ahead of target2 based on player direction, should i use something like this?

If(player.InverseTransformPoint (Target1.position) .z < player.InverseTransformPoint(Target2.position) .z)

This would give me true if target1 is behind target 2 in the direction the player is facing, is that correct?
because considering the perspective of the player inserted with InverseDirection the more you move away from the player and the larger the Z axis will become, right?

I think that’s correct. You should of course do the usual test & debug thing.