AI Issues
Author |
Message |
DemonZ
|
Posted: Thu Nov 09, 2006 12:01 am Post subject: AI Issues |
|
|
Here is a little sub-program that I am trying to implement into my game, which is a basic ai that tracks your circles x position and rotates accordingly to where you are on the screen, moves to your x coordinate, rotates back, and fires, sounds complicated? its not, my only problem is I had to use process to fork the ball controls and the AI itself, but I dont know how to combine them both into one giant loop, without one going off and the other pausing, anyway here is the source code, run the program, and youll understand what I mean, oh yeah, there is also an issue with the tank turret (gun) not lining up with my ball. If anyone can help me solve this problem, it would be very appreciated and a huge help.
Description: |
|
Download |
Filename: |
Computer A.I..zip |
Filesize: |
23.69 KB |
Downloaded: |
63 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
NikG
|
Posted: Thu Nov 16, 2006 11:04 am Post subject: (No subject) |
|
|
I haven't looked at your code since I don't have Turing on this computer, but I can tell you that it's never neccessary to use processes... there's always a better alternative (maybe not better in other languages, but definitely so in Turing).
All you need to do is keep track of all your circle variables globally (i.e. x & y position, turret angle...).
Then in each iteration of the loop, you need to determine if an update is necessary and run your "ai" procedure/function accordingly.
So if the user hasn't clicked a location, no update is neccessary and the circle can just stay still. Once the user has clicked, send the ai proc the updated position and let it calculate how much of a step it needs to take in this loop iteration.
Hope that made sense.
Onto your next problem: I'm assuming you circle is a tank with a turret and you're having a problem when you shoot because the ball (shot) comes from the centre of the circle and not the turret.
If that assumption is correct, here's the solution:
since you know the position of your circle and the angle it's facing, you can get the exact position of your turret using a little trig. Once you have that, just make that the starting position of the ball and send it along its way.
I'll try and take a look at your code later, but let me know if you need further clarification on anything in the meanwhile.
|
|
|
|
|
|
DemonZ
|
Posted: Thu Nov 16, 2006 10:25 pm Post subject: (No subject) |
|
|
nope so far i get it, but when you said put the ai into loops, wont that pause my input controls on moving the circle?, because 2 loops cannot run concurrently, so since th ai loop is the first one, I will not be able to move the circle because the ai loop has not finished.
|
|
|
|
|
|
NikG
|
Posted: Fri Nov 17, 2006 10:53 am Post subject: (No subject) |
|
|
You're close to understanding what I meant.
Ideally, a well structured program should have only ONE main loop. Any more and you're not doing something right.
So now you're probably asking "How can have one loop when I need two: one for AI and one for keyboard/mouse input?"
Just think about it for a second. The only reason you think you need two loops is that they both do something different, but isn't it possible to do what you need to do for both together?
So now I'll stop being vague and actually help:
Your AI proc should NOT contain any loops. Instead, you need to keep variables to trigger events (boolean variables can help here!). The AI proc will just check what those variables are now, and act accordingly.
So, what you'll end up with is one main loop which does everything in your program: receive input, draw the screen, and call the AI proc, which will automatically decide if updates need to be made to your variables.
I wish I could give you a little sample code, but, like I said, I don't have Turing here. You could search this site for TheOneTrueGod's rpg/rts-type game (Lost Magic I believe). Also, you could take a look at my FP submission (an rts engine), but that doesn't come with any code.
Good luck.
|
|
|
|
|
|
DemonZ
|
Posted: Fri Nov 17, 2006 4:44 pm Post subject: (No subject) |
|
|
ok thanks alot ill try somesort of boolean trigger events to get it up an running, i can get the controls and ai to almost work but I need to cut down the loops for the ai, thanks alot for the help.
|
|
|
|
|
|
|
|