AI questions..pathfinding..

andreww
03-04-2002, 09:37 AM
ok i am making a tank game in a city...
the city will basically be just a bunch of same sized city blocks with different building pictures

so the buildings will be layer out in rows with spaces around each block, everything is aligned basically..

anyway I want one tank to be able to move towards another tank...ive worked out the targeting code, so
tank A wants to move to tank B's position, or within firing range

heres an example of my city blocks

||| ||| ||| |||

||| ||| |||

||| ||| ||| |||

||| ||| |||

Squirm
03-04-2002, 10:45 AM
Despite the thread title, I couldn't find a single question in there. :D

So whats the question? :confused:

NoMoreSecrets
03-04-2002, 10:53 AM
Hi,

If u are intrested in Effective Pathfinding Algos Like(A* and Dijkstra)
There are great topic around the web, check out this link:
http://theory.stanford.edu/~amitp/GameProgramming/

But i think that those algos are to much expensive and should be used only when strictly needed.

I'll try to submit u a small solution that i think could solve your problem.

the first thing to do IMHO is to calculate the distance between

A and B and so let's start with:

Distance=[(xa-xb)^2 +(ya-yb)^2 ]^0.5

Basic trig with pithagora theorem

now u know what is the distance (TankA---TankB)

Step 1:


1) if distance <= TANK_FIRING_RADIUS then
2) TankA.Fire()
3) else
4) TankA.Move()
5) end if


(this is only for example cause u actually have to check also if there is a building between TankA and TankB)

However i'll try to solve this later on.

Step 2 (Code Line 4) :

If not in Firing radius start to move in the TankB direction


if TankA.X < Tankb.X then
TankA.X=TankA.X + vel
else
TankA.X=tankA.X-vel
end if

if TankA.Y < Tankb.Y then
TankA.Y=TankA.Y - vel
else
TankA.Y=tankA.Y + vel
end if



this is a basic follow code, during iteration u have to check if
way is blocked by building)

if the way at CellX-CellY where u are going to move is blocked by building (you told me that the rows of the city are spaced by a fixed step) move by one step to the left,right until a free space is fond and then restart the follow code


if Cell(X,Y)= NotWalkable then
Move left or right until a free vertical spot is found (TankA.X=TankA.X +/- vel)
end if




Another way to find the path and direction is to use the direction vector
using the properties of triangles u could know the angle between TankA and TankB and then set the direction according to the angle.

Let me know if u need the direction code




I'm really sorry for my english (i know that it sucks) but i hope
that u are able to understand what i'm tryng to explain

:D

Byez
Lorenzo

andreww
03-04-2002, 10:53 PM
yea im using angles, ive already got that.

, also with the tiles, is it possible to make them without changing the scale mode of the screen, like leave it as pixels..i dont know if this is the right way of doing them, but what ive been doing is changing the scale of the screen width and height

but this usually made it hard as i needed the screen in pixels

AcidBoot
03-05-2002, 01:53 AM
Pathfinding on a grid is pretty easy, depending on how cluey you want your AI to be.

At a simple level, every time your AI tank reaches a junction it checks to see where it's target is, and heads in the street most resembling that direction. So if the enemy is 3 blocks left, and two blocks up, the AI will head left.

If the x and y ranges are the same, you could have it decide based on the facing of the enemy. So if it is 2 blocks left and 2 blocks up, and it is facing right, it is a fair bet that it will next arrive at 1 block left and 2 blocks up. So the AI heads up.

It will obviously get a little trickier if you want your AI tanks to be able to change direction mid-street, or if you want a team of them to work together. Likewise if you want the tanks to be able to maneuver in the streets (ie: drive on the left or right side of the road, cut corners, etc...)

The method above needs some modification if you just want the tanks to go somewhere that they can shoot from. It is easiest if you can express thier gun range in terms of blocks. Eg: If each block is 100x100 pixels, inlcluding the street, and the tank's range is 250 pixels, then the range is 2.5 blocks. Then you make a cross centered on the target, calculate the distance to the nearest part, and head there using the above method.

Again, this can get more complicated. You may want your AI tanks to not just move out in front of the player's gun, or to get caught in a crossfire, for example.

andreww
03-05-2002, 02:38 AM
yea i want my tanks to cut corners etc,
also if a friendly tank moves in front of a firing tank, the tank firing will stop firing until the friendly tank is out of the way


what i thought of doing is moving in a straight line towards the target and just moving around obstacles as they come up,
as nomore said you can just make the tank movearound an object until it can continue its journey towards the target,

so im going to try that

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum