custom response for collisions and

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
kilnan
Posts: 7
Joined: Thu Apr 02, 2009 9:42 pm

custom response for collisions and

Post by kilnan »

Hi all,

I'm making an old school shooter in 3d (so 3th person, shoot and dodge).

I've understood that's pretty easy doing these two things using irrlicht:

- avoid collisions using a collision response animator
- get everything that is hit by a line : useful if you'r making a fps and you want to know if you get someone when you shoot

Since i'm making another kind of game, i need to handle in a custom way my collisions.. so I need to be able to detect whenever my bullets (which shall be represented by objects moving on the screen) hit the player or an enemy, and handle that situation in my game engine. Also I have to know if my player hit a monster and destroy that monster (I know, it sounds stupid), detect whenever i get an object..

I'v found out that I can do it by using getCollisionResultPosition, by checking the triangle of collision.

So .. ok, I made it somehow.. but in this way I have to make really a lot of controls, since I have to call that method for every kind of collision: for every bullet, I have to check if it hits an enemy, cycling that function for any enemy.. that's because I can't use the triangle returned by the method to get to the model which made the collision!! I just check that triangle to understand if i hit something (this is so if the triangle I get back is different from the default triangle made by 3 vertices of 0,0,0)

I use a metatriangle with all the stupid things (parts of the map which are just an obstacle) to check whenever it could hit a wall or something, since in that case I just have to remove the bullet.. but for everything which requires an intelligent control i have to make plenty of cycle..

So I'm just asking myself if is there a more intelligent way to do it.. so..

1- When I use a meta triangle selector, is there a way to get back from the triangle of getCollisionResultPosition which is the single selector (or node connected to it ) that in fact made the collision?

2- is there a more intelligent way to do it using some kind of function or an animator?

I made a few searches through google and I found out nothing.. I should open a project and try to understand but I think that someone could answer easily this question...

Thank you!!
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

You can use getSceneNodeAndCollisionPointFromRay from the ISceneCollisionManager interface.

Code: Select all

		\param ray: Line with which collisions are tested.
		\param outCollisionPoint: If a collision is detected, this will contain the
		position of the nearest collision.
		\param outTriangle: If a collision is detected, this will contain the triangle
		with which the ray collided.
		\param idBitMask: Only scene nodes with an id which matches at least one of the
		bits contained in this mask will be tested. However, if this parameter is 0, then
		all nodes are checked.
		\param collisionRootNode: the scene node at which to begin checking. Only this
		node and its children will be checked. If you want to check the entire scene,
		pass 0, and the root scene node will be used (this is the default).
		\param noDebugObjects: when true, debug objects are not considered viable targets.
		Debug objects are scene nodes with IsDebugObject() = true.
		\return Returns the scene node containing the hit triangle nearest to ray.start.
		If no collision is detected, then 0 is returned. */
		virtual ISceneNode* getSceneNodeAndCollisionPointFromRay(
								core::line3df ray,
								core::vector3df & outCollisionPoint,
								core::triangle3df & outTriangle,
								s32 idBitMask = 0,
								ISceneNode * collisionRootNode = 0,
								bool noDebugObjects = false) = 0;
For this to work, you need to set the triangle selector for nodes, like this.

Code: Select all

ITriangleSelector *pSelector = <obtain selector>;
pNode->setTriangleSelector(pSelector);
pSelector->drop();
When calling getSceneNodeAndCollisionPointFromRay, it will traverse all the nodes in the scene graph. If the node has a triangle selector set(as done abode) it'll be checked, otherwise ignored.
So you don't even need to use a metaselector =]
kilnan
Posts: 7
Joined: Thu Apr 02, 2009 9:42 pm

Post by kilnan »

thanks for the quick reply

I've understood how to use that function but I 'm still not sure about how use it in my program. If i want use that function to see if a bullet is hitting an enemy, should I see my movement vector as the ray?


[anyway, I asked if it was possible to get directly the node from the other method: seems like getCollisionResultPosition in irrlicht 1.7 (i'm still using 1.5) returns also the node of the collision...duh...]
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Gosh, i made assumptions there >.<
I assumed you were tracing plain old rays. Sorry for posting misleading information without checking the facts first.
Anyway, maybe an upgrade is in order then :)
kilnan
Posts: 7
Joined: Thu Apr 02, 2009 9:42 pm

Post by kilnan »

thanks anyway!

now.. I'm having an embarassing trouble... I downloaded irrlicht 1.7 and I'm trying to use that method but I can't!

seems like someone else had this problem...

http://irrlicht.sourceforge.net/phpBB2/ ... ltposition

but still i don't understand!

Code: Select all

 core::vector3df muoviElissoideSelettore(bool &collide,
      irr::scene::IMetaTriangleSelector * selettoreGlobaleMappa,
      core::vector3df nodePosition,
      core::vector3df ellissoide,
      core::vector3df movimento)
      {
         bool falling;  
         core::triangle3df triangolo,triangolo2;  
         core::vector3df prossimaPosizione;       
         prossimaPosizione=gestoreScena->getSceneCollisionManager()->getCollisionResultPosition(	
         selettoreGlobaleMappa,
         nodePosition,
         ellissoide, //elissoide della collisione
         movimento, 
         triangolo,
         falling
         ) ;
        
         if (triangolo==triangolo2) collide = false;
         else collide=true;
        
         return prossimaPosizione;
      }
compiler says that the method doesn't match! this is the firm of the method..

Code: Select all

	virtual core::vector3df getCollisionResultPosition(
			ITriangleSelector* selector,
			const core::vector3df &ellipsoidPosition,
			const core::vector3df& ellipsoidRadius,
			const core::vector3df& ellipsoidDirectionAndSpeed,
			core::triangle3df& triout,
			core::vector3df& hitPosition,
			bool& outFalling,
			const ISceneNode*& outNode,
			f32 slidingSpeed = 0.0005f,
			const core::vector3df& gravityDirectionAndSpeed
			= core::vector3df(0.0f, 0.0f, 0.0f)) = 0;
it's almost the same I was using before, except for the parameters outNode and hit position, so the problem should be there.. I feel like I'm dumb :oops:
CuteAlien
Admin
Posts: 10039
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Create:

Code: Select all

const ISceneNode* outNode; 
and then pass outNode to the function (just as that - references are passsed the same way as normal variables).

Also for later questions - never say "compiler says that the method doesn't match! ". Because the compiler gives a lot more detailed information (in this case it would most likely tell exactly which parameter is wrong). So please always copy&paste the exact error-message if you have one. Compiler-errors are there to help :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kilnan
Posts: 7
Joined: Thu Apr 02, 2009 9:42 pm

Post by kilnan »

I made another mistake, that was not the invokation i was making, indeed that is the one I used with irrlicht 1.5..

but I've found out the error, I used
scene::ISceneNode *outNode;
instead of
const scene::ISceneNode *outNode;
so.. thanks Alien! :)

I didnt post the compiler error since it looked too much confusing compared to the invokation and definition of each identifier... next time I'll do it! thanks again!
Post Reply