Any easy way to check for collision?

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
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Any easy way to check for collision?

Post 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?
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post 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
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post 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! :D
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post 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?
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post 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.
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post 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
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post 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...
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post by humbrol »

awesome worked great. =)

now is there a way to make the node impassable? or stop the camera from moving through it?
ertae
Posts: 7
Joined: Thu Nov 15, 2007 9:27 am

Post 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
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post 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!
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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()
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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 !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

EDIT: Sorry, didnt read the entire thread.

Read my 2nd post over, in there is a perfectly working collision function :)
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
ertae
Posts: 7
Joined: Thu Nov 15, 2007 9:27 am

Post by ertae »

i see my error thanks
Post Reply