-
Artificial Intellegence in a race game
Hi guys. I'm in the process of programming a top-down race game on box2d. Well, I've already created a car, and I know how to make it move manually using the keyboard, but I have no idea of how to make the car move itself finding the right way and even if goes off the road, find a way back to it.
Any ideas?
Or maybe someone knows good books or blogs or any others stuff about programming an AI in flash games?
Any help would be welcome
I'll be especially good to get some advices from the one who have already programmed games on box2d
I found a couple of books, actually, but they all whether too primitive or too abstract.
Last edited by caseyryan; 06-15-2010 at 07:09 AM.
-
Senior Member
forget box2d, do you even know how to program the AI if it was a normal top-down racing game? Box2d is just a physics engine, the gameplay logic is entirely separate from it.
That said, I will give you a simple hint.
1) Setup waypoints, as movieclips or just a set of coordinates in an array. When the car passes one of the waypoints, it just has to move towards the next, and so on.
2) To behave normally, you have to use add Impluse and add force, think where each will go
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
The game lil racerz inspired me to use box2d I've decompiled it to see how it works but the decompiler spoils a lot of code, that's why I decided to ask here.
I need a lot of box2d functionality in my game cuz I want the cars to collide with each other and other objects as realistically as possible
1) Setup waypoints, as movieclips or just a set of coordinates in an array. When the car passes one of the waypoints, it just has to move towards the next, and so on.
2) To behave normally, you have to use add Impluse and add force, think where each will go
hm.. thanks for the hint
Well, I guess I have to try and apply it to box2d bodies, maybe using some joints attached to these waypoints' coordinates
Last edited by caseyryan; 06-16-2010 at 09:37 AM.
-
Flash Intermediate
Actually, I'm interested in this too, bluemagica. I'm not building one of these, but I always wondered how the AI worked. You said something about impulse. I assume that it makes the CPU drive with more fails. How in the heck do you handle impulses, driving around other enemy cars, and accidental pileups?
In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.
---
Check out my blog at XenElement.com
-
Senior Member
@caseryran: did you even understand a word I said? Stop thinking in terms of box2d, it has nothing to do with your game's logic......and why the hell would you need joints? The bodies just need to move towards a waypoint, not swing around it.
@XenElement: The trick in making the AI behave realistically is in programming it the same way you are programming the player controlled version, and then simulate the player controls. Anyway, you need to first understand the force and impulse in the box2d world, so, though already outdated, read this tutorial http://www.emanueleferonato.com/2010...icable-forces/
The benefit of using box2d is that it will handle the crashes and piling-up of cars on it's own, you just need to define the driving behavior.
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
@caseryran: did you even understand a word I said? Stop thinking in terms of box2d, it has nothing to do with your game's logic......and why the hell would you need joints? The bodies just need to move towards a waypoint, not swing around it.
Well, maybe I misunderstood something. I've just never programmed anything like this, neither in simple flash nor in box2d.
So I have to figure out how to make the cars move from one waypoint to another
I suppose I have to set some waypoints and their angles. Then give their coordinates to a car (from an array, maybe) and its angle so the car knew where to rotate. Then it will accelerate just like the players car (as you said)
Last edited by caseyryan; 06-16-2010 at 11:04 AM.
-
Senior Member
do it one step at a time..... otherwise you will just lose yourself!
First forget rotation....just set three to four waypoints in a straight line along a single axis, preferably the x axis and work on getting a body to move to them in order.
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
Ok, thanks for advices. I'll do it as you said
-
You'll find this covered by Klas Kroon (check the FLA in this link - it's AS1 but all the basics are there):
http://oos.moxiecode.com/tut_06/index.html
-
That seems to be exactly what I need. Thanks
-
Glad it helped, it's basically what bluemagica was describing. It's pretty easy once you understand the concept. Let us know if we help you translate the AS1 code to AS3.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|