it does
collision sprite
Okay, if your collision is working, and your animation timer is working then what is the problem? Just toggle your animation sequence upon collision.
Programmer and 3D Artist
So, in my little experiment, I haven't implemented response animations yet based on aabb collisions, but, if I did.
I would have a function in my game object that would set its action to "Hurt", likely using an enum to enumerate different actions, which would coincide with animations. I would probably name it something like "onHit" or something similar.
In my collision loop, when detecting aabb collisions, I'd likely use my existing callback function to kind of interrupt the current animation playing for my object getting hurt. During that callback, I would check whatever logic was necessary to figure out if I should call the onHit function of the object being hit.
I'm on my phone rn so I cant really pseudocode it for you. But basically, Rutin gave you the answer, but how you accomplish that is really dependent upon your current setup.
17 hours ago, Rutin said:Okay, if your collision is working, and your animation timer is working then what is the problem? Just toggle your animation sequence upon collision.
I am trying to toggle the animation sequence upon collision but it does not work for some reason, it looks like it should work.
30 minutes ago, phil67rpg said:I am trying to toggle the animation sequence upon collision but it does not work for some reason, it looks like it should work.
Since you're using time and not ticks the general idea is to set frames based on (x) time passed.
Once your collision detection is true you would then activate your animation sequence. You then set the draw frame based on time passed, and you use that draw frame variable to determine which part of the texture to draw in your animation strip.
I would suggest you do the following:
Create an animation manager that can be used with any object with the following features.
- Ability to set how max frames and time per frame in ms
- Ability to set and check if the animation sequence is running
- Ability to check on how much time has passed since the animation started
- Ability to check which frame you're supposed to draw based on how much time has passed
- Setting the offset amount to grab part of the texture in your animation strip based on the active frame
- Ability to end the animation sequence once the final frame has been reached
This is a basic outline and should be enough to get you started. Your problem is no longer a 'collision' problem, it's now "How do I create an animation sequence?".
Also -- Based on your code, if you're putting the updated animation frame code in drawcollision_one(); how do you expect to see the result of the animation once the collision is done and it's no longer calling that function due to no collision happening anymore? If the bullet hits the plane and keeps going or is destroyed on impact it's no longer colliding, therefor you wont see the updated frames because drawcollision_one(); isn't calling.
It makes more sense to check for collision, then toggle the animation sequence independent of actual collision happening again after the check...
Programmer and 3D Artist
well to test my code I have the planes collide when I put an exit(0) in my collision detection algorithm it exits the screen. however when I put my drawcollision_one() function in the collision detection code it does not draw a collision sprite. thanks rutin. I am really trying to solve this problem. I am going to work on this problem more.
39 minutes ago, phil67rpg said:well to test my code I have the planes collide when I put an exit(0) in my collision detection algorithm it exits the screen. however when I put my drawcollision_one() function in the collision detection code it does not draw a collision sprite. thanks rutin. I am really trying to solve this problem. I am going to work on this problem more.
Okay. The solution to your problem is simple. Do what I posted above and run the animation sequence under your logic loop. Simply have a check that will see if plane.animationActive() == true then do what you need in there and update in the draw phase. The only thing your collision should be doing is setting the animation to active for the appropriate objects when collision is true, then you run your sequence under your logic step until it ends and set your animationActive to return false for that object. Your draw step will reflect which frames are active for each object.
Apart from coding this for you, I have no other way which I can simplify the concept so hopefully you can figure it out.
It's better to do things more logical as opposed to slapping together a band-aid approach when programming.
Programmer and 3D Artist
Putting exit in code to debug is not something I would recommend.
Research breakpoints and debugging.
Hello to all my stalkers.
I have made some progress, I am able to draw a collision sprite when my planes collide. all I want to do is animate the sprite sheet. here is my updated code. I just need a little hint, I have almost solved my problem.
void timer(int val)
{
screen += 0.1667f;
if (screen >= 1.0f)
{
screen = 1.0f;
}
glutPostRedisplay();
glutTimerFunc(500, timer, 0);
}
void drawcollision_one()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[3]);
screen = 0.0f;
glBegin(GL_POLYGON);
glTexCoord3f(0.0f + screen, 0.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glTexCoord3f(0.167f + screen, 0.0f, 0.0f);
glVertex3f(0.5f, 0.5f, 0.0f);
glTexCoord3f(0.167f + screen, 1.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glTexCoord3f(0.0f + screen, 1.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void coll_plane_one()
{
//draw bullet
float x = -5.0f + horizontal;
float y = 0.0f + vertical;
float oWidth = 1.0f;
float oHeight = 1.0f;
//draw plane
float xTwo = 5.0f + horizontal_one;
float yTwo = 0.0f + vertical_one;
float oTwoWidth = 1.0f;
float oTwoHeight = 1.0f;
if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
{
drawcollision_one();
}
}
my screen variable works when I set it to 0.0f, my problem is in getting the timer function to execute.