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
tank tracks movement
tank tracks movement
- Attachments
-
- tank.png (4.73 KiB) Viewed 3850 times
-
- main.cpp
- tank movement code
- (4.42 KiB) Downloaded 217 times
- DevUrandom
- Regular
- Posts: 1690
- Joined: 31 Jul 2006, 23:14
Re: tank tracks movement
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.elio wrote:- tank should turn when driving backwards if target is more than x distance away
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.)
g++ -o tank main.cpp `sdl-config --libs --cflags` -lm -lSDL_gfelio wrote:gcc -o tank main.cpp `sdl-config --libs --cflags` -lm -lSDL_gfx -lstdc++
Re: tank tracks movement
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 treadsDevUrandom 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.
Re: tank tracks movement
atm i'm using progressive speed (like there are two motors) i'll implement some gear ratios
wonderful, i try to implement more such human (= rational) behaviour.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.)
- DevUrandom
- Regular
- Posts: 1690
- Joined: 31 Jul 2006, 23:14
Re: tank tracks movement
Sounds logical. Another modificator for your algorithm.kage wrote: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 treadsDevUrandom 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.
Re: tank tracks movement
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
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
- Attachments
-
- working-copy.zip
- tank track algorithm
- (46.31 KiB) Downloaded 194 times