Simple "TPP" and collision between...

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
M!

Simple "TPP" and collision between...

Post by M! »

I know, I'm annoy, but ...

I've posted in the "Beginners Help" but none of good response was there (sad but true). I've come here and ask: How to create and recognise collision detection between bullet and opponents? I'm know there are simillar posts on forum, but there are only theory, any good example :( I've wrote a simple "TPP" game called "Rozpierdalacz" (name is in Polish because I'm from Poland) and got that problem with collision. How to write that one? Like that?:

Code: Select all

// sm - SceneManager
if (sm->getSceneCollisionManager ()->getCollision_ (bullet) == sm->(...)->getColliosion_ (opponent))
{
	opponent.live = false;
	++numOfKills;
}
LINKS:
link to the binary: http://exec0.fm.interia.pl/Rozpierdalacz.rar (1,1MB)
link to the source: http://exec0.fm.interia.pl/Rozpierdalac ... source.rar (15kB)

Below are two screenshots:
Image


Any help wanted!
If anyone want, have time or is beneficent, then he can improve the code directly in source and send it to me :)


email:
exec (delete_@_me) o2.pl
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Collision checking on bullets is expensive (because there are likely to be so many of them) and difficult to make accurate because the bullets move so fast. A simpler is to do a raycast and determine the target when you fire. To allow enemies to dodge you can make another check when the bullet reaches where it's target should be and if it is not then to continue on its path. This does not allow something to jump between the gun and it's original target, but it does allow dosging.

I'm not saying collision detection on bullets is impossible, but difficult and computationally expensive. I think that irrlicht's collision detection is too slow to be able to handle many bullets and probably not accurate enough to deal with the speed (though I'm really unsure about the accuracy). A dedicated physics engine like Newton is much faster, however I remember a post on the Newton forums about bullets in which Newton's creator said that the size to speed ratio of a bullet was too small for accurate collision detection.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
M!

Post by M! »

OK. But how to write that raycast? In Thechdemo collision with wall looks like that:

Code: Select all

if (sm->getSceneCollisionManager ()->getCollisionPoint (line, mapSelector, end, triangle))
{
	// collides with wall
	(...)
}
else
{
	// doesnt collide with wall
	(...)
}
And how do I check collision with opponent when I'm shoot? Is there any chance to check which opponent was killed? Plz give me example code, not only a theory :twisted:
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

sorry it's not much code, but one fairly simple function call

Code: Select all

ISceneCollsisionManager *collmgr=smgr->getSceneCollisionManager();
ISceneNode *target=collmgr->getSceneNodeFromRayBB(line,bitmask);
bitmask is an integer which is used for node selecting. The function returns the closest node the line would hit that has an ID which when ANDed (&)with the bitmask is !=0. If the bitmask is set to 0 then it is ignored. line should be a line3d<f32>. Use the line your gun is shooting along. Once you have your target node, if the node has a triangle selector assigned you can use the getCollisionPoint function to determine exactly where on the target the hit is. Note that getSceneNodeFromRayBB only uses bounding boxes so you will probably want to test for collision with the world geometry seperately as it's bounding box is so large as to be useless
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Post Reply