Sign in to follow this  
Jamie Cox

XNA Ghost Attack Behaviour

Recommended Posts

Hi all,

I am trying to create a game where the player is attacked by various types of ghosts. I am having trouble making the ghosts wait for a set amount of time after colliding with the player. I am attaching a file that contains the code where interactions are checked, and the Attack() method.

 

Any help would be great as I have very little XNA experience.

Edited by StuckInTheGame

Share this post


Link to post
Share on other sites

Most likely, your BoundBox.Intersects() function never returns TRUE. Probably because your collision response has already been applied somewhere in another part of your code, which pushes the bounding boxes away from each other? Then you need to figure out another way to detect collisions.

 

And if that's not it, then it's most definitely because your "float time" variable is not static or global, so it gets set to 0 every frame (or every time you call the Attack() function), and then to the elapsed frame time, instead of accumulating the time since the collision was detected.

 

Also, you shouldn't use floating point variables for storing time values, since most of the system functions return time values as an unsigned integer. If you convert the system's time values to float, aside from that extra conversion, you're also just throwing away bits of precision, and forcing floating point operations where integer operations would be sufficient (and faster).

Edited by tonemgub

Share this post


Link to post
Share on other sites


Also, you shouldn't use floating point variables for storing time values, since most of the system functions return time values as an unsigned integer. If you convert the system's time values to float, aside from that extra conversion, you're also just throwing away bits of precision, and forcing floating point operations where integer operations would be sufficient (and faster).

XNA's GameTime class uses TimeSpan structures, which return seconds as doubles.

 


And if that's not it, then it's most definitely because your "float time" variable is not static or global, so it gets set to 0 every frame (or every time you call the Attack() function), and then to the elapsed frame time, instead of accumulating the time since the collision was detected.

This.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this