Hi, guys!

Previous thread here (not necessary to read)

I’m back again, still with this AI aiming system.

I am actually having trouble with predicting where the ship will be in *x* seconds.

I can calculate the seconds it would take, I just do not know how to calculate where the ship will be (in essence, how to get its speed ).

I would use rigidbody.velocity, but my ship is moved using transform.Translate.

Does rigid body.velocity still work? Because when I used that method, and assigned the base unit to 0 (making the enemy have have pinpoint accuracy), the z vlue was always right on because I was just using the target’s z value (it never changes), but x and y would sometimes be up to 60 units off.

I think I just need a bit of a refresher on how the math would go.

The aiming script is here:

```
#pragma strict
@HideInInspector
var stats : EnemyStats;
@HideInInspector
var ship : Player;
@HideInInspector
var shipMovement : ShipMovement;
var myTarget : Transform;
var myBullet : Transform;
function Start () {
stats = transform.parent.GetComponent( EnemyStats );
ship = GameObject.Find("Master").GetComponent(Master).slotArray[Master.currentSlot].ship;
shipMovement = GameObject.Find( "Ship" ).GetComponent( ShipMovement );
myTarget = GameObject.Find( "Ship" ).transform;
}
function Shoot(){
//Calibration
var baseUnit : float = 0.0; //Haven't yet decided how much of a unit a base unit should be.
var baseAccuracy : float = stats.accuracy;
var randomAccuracy : float = Random.Range( 1.0, 2.5 );
var damagedAccuracy : float = ( stats.hp.current <= ( stats.hp.max )/2 ) ? 1.5 : 1;
var playerMoveAccuracy : float = 1.0;
if( ship.state == PlayerState.Moving ) playerMoveAccuracy = 3.0;
if( ship.state == PlayerState.Charging ) playerMoveAccuracy = 1.5;
var accuracy = baseUnit*baseAccuracy * randomAccuracy * damagedAccuracy * playerMoveAccuracy; // This defines the radius of our aiming circle
var zLeg : float = myTarget.position.z - transform.position.z;
var xLeg : float = shipMovement.x * (zLeg / 200); // These give me the speed
var yLeg : float= shipMovement.y * ( zLeg / 200 ); //200 is the speed of the bullet
var aimCircleOrigin : Vector3 = Vector3( transform.position.x + xLeg, transform.position.y + yLeg, transform.position.z + zLeg );
var aimPoint : Vector3 = Vector3(
Random.Range( aimCircleOrigin.x - accuracy, aimCircleOrigin.x + accuracy),
Random.Range( aimCircleOrigin.y - accuracy, aimCircleOrigin.y + accuracy),
aimCircleOrigin.z );
yield WaitForSeconds( 0.5 );
transform.LookAt( aimPoint );
var myBulletInstance : Transform = Instantiate(myBullet, transform.position, transform.rotation);
Debug.Log("Shot at the point " + aimPoint +". When the ship was at the point " + myTarget.position );
}
```

and if anyone wants to see how I am getting the speed of the ship, the ShipMovement script is here:

```
x = Input.GetAxis("Horizontal") * Time.deltaTime *( ( ship.state == PlayerState.Charging ) ? ship.rechargeSpeed.Value : ship.moveSpeed);
y = Input.GetAxis("Vertical") * Time.deltaTime *( ( ship.state == PlayerState.Charging ) ? ship.rechargeSpeed.Value : ship.moveSpeed);
transform.Translate(x, y, 0, Space.World);
transform.position.x = Mathf.Clamp(transform.position.x, minX, maxX);
transform.position.y = Mathf.Clamp(transform.position.y, minY, maxY);
```

Just some simple multiplication. Nothing ridiculous.

Anything wrong here?

Thanks! - YA