A is a fishing rod tip, B is a fish. I’m trying to bend the rod towards the fish.
How can I find out the distance from object A to object B? Object B moves either left or right of object A and I need to know the value in a float or vector.
Hi derkoi,
Let me give this a go, please bear in mind I’ve done this in other 3d packages but not in Unity; unity may have a built in thing.
Plus I would love to know how pro game devs approach this problem
Given A and B, with A having a “forward” vector of sorts (basically a vector indicating the forward direction for A, pointing up)
Take a cross product between A’s forward vector and the vector (B->A). So, we now have a new vector pointing away from us, into the screen.
Again, take the cross product between the new vector and A’s forward vector. This will now give a vector pointing to the right (from the pov of our screens).
Now, if you do a dot product between this vector pointing to the right and vector (B->A), if the dot product’s result is positive, then B is to the right of A, and if it is negative, to the left. Zero values indicate it is at a right angle to A, and another dot product with the forward vector and (B->A) can be performed to determine if it is pointing in the same direction as A or away from it.
HTHs!
@Marrk - the distance method returns the distance between two points; OP needs to know if a point is to the right or left of a vector.