tank tracks movement

Other talk that doesn't fit elsewhere.
This is for General Discussion, not General chat.
Post Reply
elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

tank tracks movement

Post by elio » 07 Jul 2008, 20:24

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
Attachments
tank.png
tank.png (4.73 KiB) Viewed 2809 times
main.cpp
tank movement code
(4.42 KiB) Downloaded 171 times

User avatar
DevUrandom
Regular
Regular
Posts: 1690
Joined: 31 Jul 2006, 23:14

Re: tank tracks movement

Post by DevUrandom » 07 Jul 2008, 23:40

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

User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: tank tracks movement

Post by kage » 08 Jul 2008, 00:35

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 :)

elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

Re: tank tracks movement

Post by elio » 08 Jul 2008, 09:14

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.

User avatar
DevUrandom
Regular
Regular
Posts: 1690
Joined: 31 Jul 2006, 23:14

Re: tank tracks movement

Post by DevUrandom » 08 Jul 2008, 12:24

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. ;)

elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

Re: tank tracks movement

Post by elio » 12 Jul 2008, 15:21

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
Attachments
Bildschirmfoto-tank-movement.png
tank track algorithm
working-copy.zip
tank track algorithm
(46.31 KiB) Downloaded 146 times

Post Reply