Pathfinding
I don''t know if pathfinding is quite the right term, but it''s the closest I can think of. I''m simply trying to get a character to turn and move toward a point. Basically I have a 3 space location (x, y, z) a forward vector, and a goal location (also x, y, z). I calculate the vector from the character location to the goal location, and then try to rotate toward that vector (ie find the shorter rotation direction so I don''t turn more than 180 degrees).
I don''t know if my method is odd or completely out there, but I''m using the slopes of the forward vector and the vector to the goal location to figure out which way to turn. The problem is somehow (perhaps due to floating point error) it sometimes makes odd choices as to which way to turn, and sometimes doesn''t seem to think it should turn when it should.
I could really use some tips on at least how to figure out which way to turn (clockwise vs. counter clockwise) so that it''s the shorter actual rotation (ie no more than 180 degrees).
Thanks
PS the code confuses even me, but if you need to see it, I can post it.
April 23, 2003 03:23 PM
This is what I use
angle=angle+sign(angdif(angle,targetangle))*turnspeed
Function float angdif(float currentangle,float newangle)
currentangle=newangle-currentangle
If currentangle>+180 Then Return currentangle-360
If currentangle<-180 Then Return currentangle+360
Return currentangle
EndFunction
angle=angle+sign(angdif(angle,targetangle))*turnspeed
Function float angdif(float currentangle,float newangle)
currentangle=newangle-currentangle
If currentangle>+180 Then Return currentangle-360
If currentangle<-180 Then Return currentangle+360
Return currentangle
EndFunction
How do you get the angle between the two vectors? I was using the dot product, but that really only gives you a value from 0 to 180, which doesn''t tell me which direction it''s really pointing.
More accurately, how do you get "targetangle" from the vector between the character and the goal point? If I were to do a dot product with the vector and the X-axis, it won''t tell me if the vector is above or below the x-axis, so it doesn''t really help.
April 25, 2003 03:25 AM
http://www.cs.unc.edu/~geom/collide/index.shtml
check this out, pretty good material
check this out, pretty good material
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement