Ennemie hit player

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Ennemie hit player

Post by goutbouyo »

Hi,

I use the shoot() function in the demo for my monsters' shoots.
But now, how can I see if their bullets touch me ???

Do you have ny idea please ???
WalterWzK
Posts: 72
Joined: Wed Jan 12, 2005 2:57 pm
Location: Netherlands
Contact:

Post by WalterWzK »

Well im not totally aware of the shoot() function but I think i can help you a little bit. In the SDK there is a demonstration where you see the surface of something your currently watching to is higlighted with a red-lined retrangle.
This is a form of collision detection wich would be very usefull to calculate if your 'bad-guys' have the ability to hit you or just shot the wall at wich your behind. Try understanding this code by opening the source and take a few minutes to read..

Im sure you have the capability to program a function that checks where 'you' are and then checks if its possible for the 'bad-guy' to hit you without any other surfaces inbetween. Than if it is, just play a animation of a shot and decrease the players health.

One extra tip: always add collision to 'the bullet' aswel because if there would unexpectedly come somethin between the player and the bullet it would be fair to forget about the healthloss and abort the shot.

I hope you can do somethin with my reply..
Current Project: Don Salvatore's Mafia
Genre: 3D Shooter \ RTS
Programming Language: VB .NET
Engine: Irrlicht 11 [.NET Wrapper]
Guest

Post by Guest »

maybe give the playermodel the ID number 123 and check if the bullet has hit a model with ID 123 (setID and getID functions in the api doc)
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

Hi,

I have already made a shoot() funtion :

Code: Select all

core::vector3df start(ennemi[i].x, ennemi[i].y, ennemi[i].z);
core::vector3df end = (camera->getPosition() - start);
end = start + (end * 1000);			

// get intersection point with map
core::triangle3df triangle;
core::line3d<f32> line(start, end);
SParticleImpact imp; 
imp.when = 0;

if (smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle))
{
// collides with wall
core::vector3df out = triangle.getNormal();
out.setLength(0.03f);

imp.when = 1;
imp.outVector = out;
imp.pos = end;
}

f32 length = (f32)(end - start).getLength();
const f32 speed = 1.6f;
u32 time = (u32)(length / speed);

// set flight line
anim = smgr->createFlyStraightAnimator(start, end, time);
bill->addAnimator(anim);	
anim->drop();

if (imp.when)
{
// create impact note
imp.when = now;
Impacts.push_back(imp);
}
But, now I want to know when the bullet hit the player.
Because, if the ennemi shoots while the player is moving, the bullet will not hit him.
So I thought about calculate distance between ennemie and player, then calculate the time that need the bullet to go to that position and see if at this moment the player is yet here ....

What are you thinking about that ???
Nova
Competition winner
Posts: 99
Joined: Mon May 09, 2005 10:32 am

Post by Nova »

That would include that your enemies would shoot directly at you and it wont allow for any AI sort of things, saying that the enemy is intelligent enought to shoot into your moving direction...

Besides the fact that every enemy in your game would shoot the exact same way... your way wouldn't give the opportunity to have some sort of projectile darting around your world...

It is a soulution, though not a very neat one, imo

You said that you have used the code from the techdemo, which, with the necessary extention mentioned by GFXstyLER, would fit perfectly fine i guess...
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

Hi it's me again !!!
I remade my whole game and I have this problem another time ....

My game is a FPS, so I haven't player model ....
I know that with a player model it would be easy to check collision but I don't have one.
So how can I see if an enemy hits the player ???

Have you any idea please???
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Do you actually have a projectile which flies through the air and actually takes time to travel to the player, or are the bullets instant hit?

If it's the first of those two then you can set the bullet flying and then every frame you can check the line that it's travelled along since the last frame and check to see if that has hit a wall or the player. Without having a player model you could create your own bounding box (aabbox3d) and set it to your desired size around the camera, and check if the line the bullet has flown along intersects with that box.
Image Image Image
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

I did like you say:
I create a bounding box arround the player position and then I test the collision with the bullets.

Thanks for your help !!!
Bye
Avalanche
Posts: 18
Joined: Tue Sep 05, 2006 7:21 am

Post by Avalanche »

JP wrote: If it's the first of those two then you can set the bullet flying and then every frame you can check the line that it's travelled along since the last frame and check to see if that has hit a wall or the player.
what if the framerate gets extreem bad? will the bullet passes through player?
milkshakeman
Posts: 27
Joined: Mon Aug 14, 2006 12:36 pm

Post by milkshakeman »

Hi - funny way to spell the word "enemy" by the way ;)

I just wanted to share how I did the bullet collision detection. (It is very similar to what was summarized above, but I try to explain in more detail)

I first calculate a 3D ray starting from the players gun upto some maximum distance the bullet could travel, angle of this ray = angle of the gun.
Then I use getSceneNodeFromRayBB with bitmask=5 (all the nodes in the scene that can be hit have either ID 1 or 4)
If I got a collision of my bullet ray with an objects boundingbox, then I actually do a real collision test with that object, using its triangle selector and function getCollisionPoint.
If this test failed (eg. the player shot the bad guy between his legs) then I do a bitwise OR of this node ID with 2 - so this objects BB is excluded from the next ray-boundingbox-collision test.
Then the loop starts again - maybe the next bounding box that the ray will hit is the bounding box of the floor and then the collision test will return true, because it will hit a triangle of my floor mesh. Afterwards I have to restore all node IDs back to their original state of course.

This way of collision detection works really fast and accurate - at least in my test it did.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Avalanche wrote:
JP wrote: If it's the first of those two then you can set the bullet flying and then every frame you can check the line that it's travelled along since the last frame and check to see if that has hit a wall or the player.
what if the framerate gets extreem bad? will the bullet passes through player?
It would if you just took the bullets current position and checked it with the bounding box of a player. But if you take a line from the bullets position in the previous frame and the position in the current frame then you can see if it passed through or intersects with the bounding box since the last frame, so should work fine
Image Image Image
Post Reply