Python + gun turret

Hi all,

I need for my game an algorithm for my AI gun turret.
the problem is to calculate two angle for the IPO rotation.

there are three objects :

the gun, for vertical rotation
turret for horizontal
ship for mouvement.

the gun is parented to turret and turret to the ship.

the ship is a dynamic rigid body, and so the script must take care about the position of the ship.

all my trys have failed. :mad:

can some one know how to do ?

thx :slight_smile:
you can let the turret move only horizontaly by setting the trackto on 2D

Since I was going to need a turret in my work like the one you described, I decided to work on it now for you.

It does not aim ahead like dj2k’s, but it has a base and barrel that can be rotated in any direction as you wanted. From his script you probably can make it aim ahead. Hopefully you understand how functions work so that you can just copy paste what I did into your project.

Keys for the .blend:
A - rotates Turret Cube to the left.
D - rotates Turret Cube to the right.
arrow keys - move Target Cube around.
page up and down keys - move Target Cube up and down.

P.S. I can make one for you that is 2.49 compatible if you ask for it.


Man you’re awesome, that’s exactly i need :wink:

thx !

Just for some fun, here is a video of the turret script I posted, with anticipation.