Advertisement

AI Wander and Chase States

Started by October 09, 2009 10:59 AM
0 comments, last by burnthepc 15 years, 3 months ago
Alright so I read this from a C# tutorial on creators club and tried to implement it into c++. CODE: http://pastebin.com/m29d9bb82 Now it works partially. Only problem is the enemies always turn right. And the state of chasing never activates properly. What will happen is they always circle the player turning right constantly with line "56" enabled. Now if i disable line "56" and enable line 55 chasing does activate but the image draws wrong. It's rotated 90 degrees so it's as if the tank is moving sideways. But again the tank is constantly still always turning right never left. The original code was from : http://creators.xna.com/en-US/sample/chaseevade I'm not sure which function I've done wrong if any. But I'm confusing myself with some simple trig. If anyone can see where I'm doing something wrong it'll be greatly appreciated. BTW - My radians go from 0 - Pi2 Thanks, Scott. [Edited by - Scottehy on October 9, 2009 11:21:09 AM]
I'm guessing a bit. I had a similar problem and I solved it through atan2 I think: http://en.wikipedia.org/wiki/Atan2

The issue was traditional trig functions can will return a +0-1 range. If your program uses +1 on the x coord as right and -1 on the x coord for left, then the function will always return right.

Another gotcha that I had was that I assumed that the trig functions would have an origin at the 12'o clock position (or x,y = 0,1) but they are not. Maths functions treat (x,y = 1,0) as the origin (or 3 o'clock position). I ended up subtracting Pi /2 radians to the function to change the origin to what I wanted.

All of the above may be horrible hacks, but they worked for me!

This topic is closed to new replies.

Advertisement