XNA Zombie AI

Started by
31 comments, last by Benthepen 13 years ago
The zombie is rotating with the player pretty well now but only in the bottom right 90 degrees. The update method is still referencing Game1's objects instead of zombie.Update's parameters. Here's the link for the new code
Advertisement

[quote name='Benthepen' timestamp='1303422985' post='4801397']
I'm experimenting and I think I might have figured it out. When I changed the zombie.Update parameters in both the class and Game1 and it said the parameters didn't exist in Game1. I think that means it has been checking the player object in Game1 instead of the parameter player.


I actually had not noticed that you had a private member in the zombie class named player. That definitely presented some conflict. I commented out that line/object.


And now it's working right.

So from your original copy I commented out in the zombie class:

private Player player = new Player();

Changing X and Y doesn't affect the position.. OH MY GOD, just realized that the rotation uses the X and Y instead of Position.X and Position.Y.



And made the zombie update function look like:

public void Update(GameTime gameTime, Player player, Bullet bullet)
{
Angle = (float)Math.Atan2(player.Y - Y, player.X - X);
Angle = (float)(Angle + Math.PI / 2);
}





Edit: Sorry, I forgot that I made one other change. In the zombie Initialize function I added:

X = 200;

Y = 300;




[/quote]
I found the problem. X and Y weren't controlling the position after zombie.Initialize so i plugged in the Position x and y to the rotation algorithm and it worked perfectly. Thanks for the help guys.

This topic is closed to new replies.

Advertisement