http://pastebin.com/iw9DHf7s is code demonstrating dot product turning a turretto a target and firing. It works and chooses best angle to spin.
A problem can occur when game goes faster (better computer) and that threshold no longer applies. Making the threshold bigger obviously stops the turret early.
My friend mentions cross product is the way to fix it. Then he disappears for long periods of time. Doesn't dot product NOT get a inner angle between two vectors? Ok lets just say I agree and dot product doesn't work ever.
So tell me how does vector product do the trick? I'm going from a single scalar that I can get degrees out of to a third orthogonal vector. I've read about cross product and the function and watched a you tube video and I don't get (given the same code pasted) how to use cross product here.
Update: Would this work?
//towerFacing is the at/forward vector of the cannon
Vector v1 = cannonPos - targetPos ;
Vector v2 = towerFacing - cannonPos ;
//The z plane
double cross = v1.x*v2.y - v1.y*v2.x ;
if (cross > 0) { return Direction.Left ; }
if (cross < 0) { return Direction.Right ; }
Obviously the zero is not what we want to use in games. However The difference is now our zero means our at vector and target is perpendicular and on each other which a x b = 0
. The dot product since it uses cosine I used the right vector which is orthogonal with the facing( a . b = 0)
.
Am I wrong on how the cross product works by what has listed for answers still?