Know if an object is between player and camera positions in material graph

We have the Player Position (a vector world space collection parameter set on char tick), then we have the Actor Position (the location of the object with the material in world space) and we know the Camera Position (camera position in world space)

How can we find out if the Actor Position is in between the Player and Camera Positions within the material graph ?

Already tried various things without succes, is there a node that does this in material graph?

---- Update

Okay the thing is, get the distance between the camera and the player, get the distance between the camera and the actor with the material to finally get the difference between them…

So if the distance between the camera and actor is less than the distance between camera and the player we know that the object is between the camera and the player then !

I got this so far but ain’t working…

What I’m doing wrong?

1 Like

Why are you masking the RGB channels of the player position immediately after the player position node? That’s cutting the XYZ coords out of it, thereby it is probably not calculating correctly because it doesn’t ‘see’ the player position in XYZ. You should also set Camera Position in the A pin for each Subtract node. So, subtract it this way:

Camera Position - Player Position (camera is in A, player is in B)
Camera Position - Actor Position (camera is in A, player is in B)

It’s probably part of why it’s not working.

The Abs node (Absolute Value) is connected to the 2Vector input on Vector Length, for each distance calculation. What’s that for? After that it’s not being used. I don’t know what the point of it was/is, but try disconnecting those in addition to rearranging the subtraction connections.

The reason to subtract with camera position in A, or first, and the other after is to get a forward vector reference (meaning the vector traveling from the camera forward into the scene, which will be utilized for comparing the two subtractions accurately, with the right reference for each in 3D space). However, it depends on the final result that’s intended too. I think it’ll be easier to work with camera in pin A. When those two calculations are done, and get absolute value is run for them, then vector length, it’s then another subtract needs to be run to determine the difference.

1 Like

Man… You’re a beast ! Thanks for this, it actually worked and I’m very happy with it now !

I’m not using the opacity nor any direction but a mask with a texture, this is the whole thing:

And this is the final [result][2]

Will mark your answer for providing the direction calculation, that was insane, thanks !

1 Like

I can’t mark your answer because it’s a comment xD please Write something !!!

1 Like

I’m masking the player position because is a float4, and thus we only need the float3 RGB as XYZ coords

You’re actually really right and on point noticing the Abs connected to the 2Vector… Was trying everything and finally got this mess!

I got this to work, thank you for your hint for putting the camera position first, that was much appreciated

1 Like

You have to calculate not only distance, but direction as well. Here’s what I came up with:

Here’s the [result][2].

Hope this helps.

1 Like

I converted it into an answer. Glad it helped you.

1 Like