Page 1 of 1
Any easy way to check for collision?
Posted: Thu Nov 22, 2007 6:59 am
by Ion Dune
I'm working on a jumping animation, and I need it only be possible when the player is standing on something. I'm using the CollisionDetectionAnimator, but gravity is set to 0 and is done otherwise, so isFalling() will not work. Besides that, is there any way to see if my character and his ellipsoid are colliding with my metaselector?
Posted: Thu Nov 22, 2007 5:12 pm
by dudMaN
Code: Select all
// Irrlicht collision [FOR MAP]
selector = smgr->createOctTreeTriangleSelector(map->getMesh()->getMesh(0), map, 128);
map->setTriangleSelector(selector); // set the map's collision tri grabber
selector->drop(); // drop it as we wont need it anymore
// Irrlicht collision [FOR P1]
ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(selector, p1->getNode(), core::vector3df(30,2,30),
core::vector3df(0,-4,0),
core::vector3df(0,0,0));
p1->getNode()->addAnimator(anim); // add the gravity/collision response animator
anim->drop(); // we dont need the animator anymore
works fine for me.
for jumping, just set a timer after they jump for the first time, and they cant jump until that expires. used it for my mario game, works good for me
-dudMan
Posted: Thu Nov 22, 2007 7:11 pm
by Ion Dune
No, I'm sorry, I think you misunderstood. I have working collision, I don't have any problem there. What I need is a way to return a value or something based on collision, so I can use it in "if" statements.
I can't use a timer because then the player would still be able to jump in the air.
Thanks for you help either way though!

Posted: Thu Nov 22, 2007 10:12 pm
by humbrol
I do not have a map loaded, trying to do a space enviroment with meshes and nodes loaded, is there a way to do collision detection between a cameranode and a sphere node or a loaded mesh?
Posted: Thu Nov 22, 2007 10:17 pm
by wildrj
id think the simplest way to do collision is to check the coordinates and make sure it isn't close to the coordinates of the *barrier* or on it.
Posted: Fri Nov 23, 2007 12:13 am
by dudMaN
Part of my tutorial is on "if statement" collision detection:
http://irrlicht.sourceforge.net/phpBB2/ ... p?p=136776 - Look at chapter 5
-dudMan
Posted: Fri Nov 23, 2007 1:49 am
by christianclavet
Have you checked the SDK manual for this class:
ISceneCollisionManager?
There is a subfunction that's named:
getCollisionPoint();
getCollisionResultPosition();
Never tried them, but should be a good place to look...
Posted: Fri Nov 23, 2007 2:20 am
by humbrol
awesome worked great. =)
now is there a way to make the node impassable? or stop the camera from moving through it?
Posted: Mon Nov 26, 2007 9:35 am
by ertae
sorry im new using irrlicht why i have these errors
1>c:\users\ertae\desktop\pixel\test2\test2\test2.cpp(195) : error C2065: 'p1' : undeclared identifier
1>c:\users\ertae\desktop\pixel\test2\test2\test2.cpp(195) : error C2227: left of '->getNode' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ertae\desktop\pixel\test2\test2\test2.cpp(198) : error C2227: left of '->getNode' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\ertae\desktop\pixel\test2\test2\test2.cpp(198) : error C2227: left of '->addAnimator' must point to class/struct/union/generic type
Posted: Mon Nov 26, 2007 10:00 am
by Saturn
Err, probably not only new to Irrlicht, but programming in general.
This snippet is nothing you can just copy/paste in your project and expect to work. You need to change it according to your needs. In this case you need to exchange placeholder p1 with an instance of whatever is your GO type.
And you need to actually *understand* what it does!
Posted: Mon Nov 26, 2007 10:00 am
by JP
define p1, presumably this is a player class, all you'd have to do is swap in your character's node instead of p1->getNode()
Posted: Mon Nov 26, 2007 1:37 pm
by Acki
Saturn wrote:This snippet is nothing you can just copy/paste in your project and expect to work.
right, this depends on all codes, especially for the tutorials !!!
don't try to only get them to work, but also try to learn what they do (how something is done) !!!
only copy/paste and get them to work doesn't get you further and is not the intention of them !!!

Posted: Mon Nov 26, 2007 8:47 pm
by dudMaN
EDIT: Sorry, didnt read the entire thread.
Read my 2nd post over, in there is a perfectly working collision function

Posted: Mon Nov 26, 2007 10:41 pm
by ertae
i see my error thanks