Tank Turret

Hi guys. can you help me understand how to create a tank which automatically will set turret and barrel toward the target? This file shows what I mean. I can rotate the turret by TrackTo or using python script, but how to force the barrel to move only up and down?
Tank_Turret.blend (501 KB)

What I used to do is make the barrel track using the exact same track to, but with 3d enabled. If the barrel is faster than the turret, slow down the barrel by increasing the track time. Really crappy method, but worth a shot?

EDIT: I tried it out, doesn’t work. It makes the barrel freak out. Sorry :\

is not a thing too easy to make ,

the best way that i know is overwrite the orientation

suppose that you run this script from the cannon obj (children of the tank)
you have to check localOrientation that give you the rotation difference with the parent obj.

so, first of all , parent the obj in the “right way” (really is a bug) ,
parent the cannon(and other piece) to the tank when the tank have a reset orientation (ALT+R)

so, suppose that you want limit the rotation on Z axis, and keep fix X and Y

#########

vec = cannon.getVectTo(target)[1]
cannon.alignAxisToVect(vec, 1, 0.1) # write

zMin = -0.2 #set the limit
zMax = 0.5 #set the limit

x, y, z = cannon.localOrientation.to_euler()
x = 0.0
y = 0.0
z = min(max(z, zMin), zMax)
cannon.localOrientation = [x,y,z] # overwrite

#########

Thanks to you both for your help. I just modified the script, to work up/down cannon use X axis, not Z, and now everything works fine :slight_smile:

Getting a turret to align to a target is actually quite a complex problem.

I’ve spent a few weeks attempting to build a comprehensive and customizable automated turret system that’s more realistic than what you get by using the track-to actuator. I’m planning to release on blendswap for people to use in their own games.

It probably won’t be ready until after new year, but I hope that when it is people will find a wide variety of uses for it.

Other things that you need to consider…

  • Turret’s parent (tank body) orientation (eg: while climbing a hill)
  • Target range
  • Target speed

sure ,there many way to do more or less this thing , but the problem is that can become a lot more long.
for example using apply rotation , you have to “predict the future”, plus when the target is centered the cannon continue to “flikering”…alignAxisToVect() is very good :wink:

alignAxisToVect I suppose is useful in some circumstances, but as far as I can see you can’t make a turret rotate at a pre-determined speed using that, nor can you limit the turret’s rotation or pitch as you would have to with a tank turret.

Gun has a trackTo target in 3d while the turret is tracking 2d and both are parented to base with a moved pivot point.
Don’t forget to apply rotation.

Attachments

Tank_Turret Fixed.blend (101 KB)

I did it by MarcoIT script, but [email protected] :slight_smile:
Tank_Turret2.blend (550 KB)

I think that I also solved this problem in my file.