If Collision Detected

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
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

If Collision Detected

Post by LunaRebirth »

Hey guys,
Another collision problem.

It's not too big of a problem, but let me explain what I'm trying to do.

I've used the following code:
scene::ISceneNodeAnimator *anim = smgr->createCollisionResponseAnimator(selector,node,core::vector3df(10,20,10),core::vector3df(0,0,0),core::vector3df(0,-25,0));

This works beautifully!
However, I'm trying to make it so if you touch the object, your animation is set to idle.

So my question is... How can I detect IF the two objects have collided?
So if I were going to std::cout "They collided!" once they hit, how would I go about detecting if they've touched or not?

Thanks in advance!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: If Collision Detected

Post by CuteAlien »

It returns a ISceneNodeAnimatorCollisionResponse* not just a ISceneNodeAnimator* and that class has functions which you can use to check the result. You can poll them or you can use setCollisionCallback to set a callback class which is run on each collision. As you probably don't want to check if it collided against the floor you might want to check if the result is above the feet of your characters before you stop it's animation.

But looking at that code I see one potential problem - this seems to only return the last collision result - which I guess might be random if you collide against a floor and a wall at the same time. And only way around that I can see right now is writing your own collision mechanism. Either using Irrlicht's collision functions or a physics engine. Sorry - that animator is nice for a quick prototype, but unless I miss something it won't be useful for a more complex handling.
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
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: If Collision Detected

Post by LunaRebirth »

That doesn't answer my question one bit.

I found the class getCollisionNode()
But I can't figure out how to actually use it??? I keep getting errors trying to do something like..
if (node->getCollisionNode() == node2)

It doesn't work...
I've also tried making it a class like so..

class ISceneNodeAnimatorCollisionResponce {
public:
virtual ISceneNode* getCollisionNode(void) {
return getCollisionNode();
}
};

which also failed.

I want to check if node collided with node2 or not
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: If Collision Detected

Post by CuteAlien »

LunaRebirth wrote: I found the class getCollisionNode()
But I can't figure out how to actually use it??? I keep getting errors trying to do something like..
if (node->getCollisionNode() == node2)

It doesn't work...
That's because getCollisionNode() is not a function for scenenodes but one of ISceneNodeAnimatorCollisionResponse. In your first post your anim variable - that can be ISceneNodeAnimatorCollisionResponse instead of ISceneNodeAnimator.

The other solution makes no sense in c++, just forget about that.
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
Post Reply