Page 1 of 1

tank tracks movement

Posted: 07 Jul 2008, 20:24
by elio
so, as my holidays started i wrote this little thing which simulates simple movement of tank tracks

well this isn't really an useful contribution to warzone2100 (should better make gfx for wz i know^^)

my further ideas were:
- tank should turn when driving backwards if target is more than x distance away
- acceleration/retardants

compiles with gcc -o tank main.cpp `sdl-config --libs --cflags` -lm -lSDL_gfx -lstdc++

- ESC to quit
- Click somewhere and the target is set there

Re: tank tracks movement

Posted: 07 Jul 2008, 23:40
by DevUrandom
elio wrote:- tank should turn when driving backwards if target is more than x distance away
As (a) forward gears are usually more powerful than backwards (assume that, am no tank driver) and (b) amor is more powerful on the front (another assumption out of thin air), this sounds like a very logical step.
Basically you should compare how long it would take to turn and drive there, with just driving backwards.
If you want it a bit more complicated, you would also calc whether turning now would require another turn for the next waypoint and add that as a penalty. (Or not add it, if the turn saves a rotation for the next waypoint.)
elio wrote:gcc -o tank main.cpp `sdl-config --libs --cflags` -lm -lSDL_gfx -lstdc++
g++ -o tank main.cpp `sdl-config --libs --cflags` -lm -lSDL_gf

Re: tank tracks movement

Posted: 08 Jul 2008, 00:35
by kage
DevUrandom wrote: As (a) forward gears are usually more powerful than backwards (assume that, am no tank driver) and (b) amor is more powerful on the front (another assumption out of thin air), this sounds like a very logical step.
afaik, traditionally if there's an enemy shooting at you (that is a reasonable threat), you put your front armor towards them, even if you need to retreat backwards (so the algorithm would be more about figuring out where the enemy is). any other time, drive forwards, since it's hard enough seeing while you're going forwards that it's not worth the risk to get your tank stuck or damaged going backwards (unless you're being fired at of course). in general, i don't think it matters either way, though, and it would look awesome just to have (visually) working treads :)

Re: tank tracks movement

Posted: 08 Jul 2008, 09:14
by elio
atm i'm using progressive speed (like there are two motors) i'll implement some gear ratios
DevUrandom wrote: Basically you should compare how long it would take to turn and drive there, with just driving backwards.
If you want it a bit more complicated, you would also calc whether turning now would require another turn for the next waypoint and add that as a penalty. (Or not add it, if the turn saves a rotation for the next waypoint.)
wonderful, i try to implement more such human (= rational) behaviour.

Re: tank tracks movement

Posted: 08 Jul 2008, 12:24
by DevUrandom
kage wrote:
DevUrandom wrote: As (a) forward gears are usually more powerful than backwards (assume that, am no tank driver) and (b) amor is more powerful on the front (another assumption out of thin air), this sounds like a very logical step.
afaik, traditionally if there's an enemy shooting at you (that is a reasonable threat), you put your front armor towards them, even if you need to retreat backwards (so the algorithm would be more about figuring out where the enemy is). any other time, drive forwards, since it's hard enough seeing while you're going forwards that it's not worth the risk to get your tank stuck or damaged going backwards (unless you're being fired at of course). in general, i don't think it matters either way, though, and it would look awesome just to have (visually) working treads :)
Sounds logical. Another modificator for your algorithm. ;)

Re: tank tracks movement

Posted: 12 Jul 2008, 15:21
by elio
here's a new version of my algorithm xD

usage:
compile, start and click somewhere in the window

there are hardly any comments in the code, but i'll add them later.

some improvements:
- forward and reverse speed limits
- tank drives backwards or turns 180° and drives forward, depending on what's faster
- when there are multiple targets. for example one near behind him and one "far" away from him he doesn't turn at all. (because he needs more time to turn than he loses with the slow reverse gear)

yet handicap:
- the more waypoints(=targets) you set, the more slowly it is (^2)

parameters to play with:
these three constants in main.h
#define MAX_SPEED 6.0f
#define MAX_REV_SPEED 4.0f
#define WIDTH 100

erm, is this enough clearly formulated? :-S