# Complex AI turret formula - Math Expert NEEDED!

**URL:** <https://forum.kirupa.com/t/complex-ai-turret-formula-math-expert-needed/178492>\
**Category:** Uncategorized\
**Created:** [February 11, 2006, 12:17am UTC](https://forum.kirupa.com/t/complex-ai-turret-formula-math-expert-needed/178492 "2006-02-11T00:17:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zicemaster](https://avatars.discourse-cdn.com/v4/letter/z/b77776/32.png) [@zicemaster](https://forum.kirupa.com/u/zicemaster)\
**Post date:** [February 11, 2006, 12:17am UTC](https://forum.kirupa.com/t/complex-ai-turret-formula-math-expert-needed/178492/1 "2006-02-11T00:17:38Z")

</div>

I am trying to make an AI turret that not only fires at the player… But also adjusts for gravity, friction, and will use angles 45-90, or 45-0 based upon if I wan’t high angle shots, or low angle shots.

I would apreciate any anything on real gravity AI turrets in C++, Jscript, or even actionscript… But I doubt if it exists in actionscript!

Here are my tries so far…  
[Attempt 1](http://photobucket.com/albums/y232/minyMonkey/?action=view&current=tankORIG.swf)  
[Attempt 2](http://photobucket.com/albums/y232/minyMonkey/?action=view&current=tank.swf)

dx/y = distances, x/ySpeed = Projectile speeds, .25 = projectile gravity, .99 = projectile friction

```auto

[COLOR=Magenta]//PROJECTILE CODE:[/COLOR]
xSpeed = xSpeed*friction;
ySpeed = ySpeed-gravity;

[COLOR=Magenta]//Attempt 1[/COLOR]
this.enemyBunkerTurret0._rotation = degrees+90-((((dx/xSpeed)*.99)+((dy/ySpeed)*.25))/2);

[COLOR=Magenta]//Attempt 2[/COLOR]
this.enemyBunkerTurret0._rotation = degrees+ 90+(xSpeed*Math.sin(dx*Math.PI/360)*.99 + ySpeed*Math.cos(dy*Math.PI/360)*.25);

```

I really am starting to get desprate here… LOL!
