AI help

I need some help with a AI script for a bird that attacks and fly form 1 spot to a nother

You need to decide if this is a physics or programmatic method of attacking. In physics you would control the turning and propulsion of your bird and let the engine handle the rest. In a programmatic method you would control the actual movement.

Let me describe the programmatic method…

To start, lets say your bird always has to be moving forward, and has a minimum speed that it can fly at. Then you need to calculate the y rotation difference between the way your bird is going, and the lookat rotation to where you want to be.

So in your movement script, you will need to first find the rotation that you need to move, and add or subtract the rotation that you can move. You can then use that y rotation to calculate a z rotation for banking. Once that is figured out, you will then want to do the same thing for your x rotation, up and down, but remember that you will need a max turning for your x and y. At this point, set your rotation.

Now, you have a y rotation difference between what you want, and what you have. That difference denotes speed. The farther away from zero (looking straight at it) is the difference in speed. You first transform the direction of your bird, and multiply that times the current speed and of course by the deltaTime. Now, adjust your movement.

So where I am not going to write all your code for you. I will give you an example from an AI script that I wrote for movement. Mind you, this is for a car, not a bird… :wink:

function FindDriveSteer(){
	//find the target angle..
	var a=transform.localEulerAngles.y;
	if(myAngle>180)myAngle=myAngle-360;
	
	// find the look rotation to the target
	var relativePos=target.position - transform.position;
	var targetAngle= Quaternion.LookRotation(relativePos).eulerAngles.y;
	if(targetAngle>180)targetAngle=targetAngle-360;
	
	// find the difference of the two angles (y rotation)
	targetAngle=targetAngle-myAngle;
	if(targetAngle>180)targetAngle=targetAngle-360;
	
	//define the steering, left or right
	steer=-1.0;
	if(targetAngle>=0)steer=1.0;
	
	//define the drive (used for vehicles to back up)
	//also, if your going in reverse turn away from the target so that your front comes to it.
	drive=1.0;
	if(Mathf.Abs(targetAngle)>90.0){
		drive=-1.0;
		steer=-steer;
	}
	
	//check the angle against the current steering velocity of the vehicle
	targetAngle=Mathf.Abs(targetAngle);
	steer=Mathf.Clamp(targetAngle,0.0,VS.veloSteer)*steer;
	
	//if the target angle is greater than 1/3 the steering velocity, lets make a slower turn.
	if(targetAngle>VS.veloSteer/3)
		drive=drive * 0.75;
}

That is a setup for a dive bombing bird. Attacking can be done many ways, for that, you would need to be really clear on how you want things to attack, and that is a whole different ball of wax.

wow thanks I’ll see what I can do with this info thank you