Jump & Collision (Answered)

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
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Jump & Collision (Answered)

Post by Yellow_Yackets »

Hi....


I am having a little problem with the camera(FPS)....

I create a plain terrain and i add a collition detector to it with the camera.
When i jump, everything seems to work very cool.... BUT

Whenever i put another object above the plane, and i jump on it.. the jump
seems to delay(on top of the added object)... also if i create a stair that goes really high, when i am on top of it, i can't jump at all... but when i fall to the ground again, i get able to jump with no problems...

Is it because the gravity or any values that im giving wrong or is just something i have to implement by coding??

This is the stair that i create, it looks crapy because i just create right now
to give a better idea of the jumping problem...
When i get on the boxes i can't JUMP....

Here i can jump..
Image


Here i can't jump!!..
Image
Last edited by Yellow_Yackets on Mon Nov 19, 2007 10:22 pm, edited 2 times in total.
Y_Y
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Post by Yellow_Yackets »

Well... i guess i have to solve this by myself... :(
Y_Y
anandh
Posts: 61
Joined: Thu Sep 14, 2006 12:40 pm
Contact:

Post by anandh »

How did u solved it.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Did you used the standard IRRlicht collision?

You must put all your object in the metaselector to have proper collision.
The boxes and stairs are added as OCCTREE in the metaselector?
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Post by Yellow_Yackets »

christianclavet wrote:Did you used the standard IRRlicht collision?

You must put all your object in the metaselector to have proper collision.
The boxes and stairs are added as OCCTREE in the metaselector?
No, i did not used metaselector on my boxes, i'm going to try it tonight.
I'll post the result after i test it.
Y_Y
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Post by Yellow_Yackets »

Well....

I was triying to figure out how to use the meta selector but it didn't worked out. This is how my code works:

Code: Select all


ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox(OJ[wh].Cube);
    OJ[wh].Cube->setTriangleSelector(selector);
    selector->drop();

aabbox3d<f32> box = OJ[wh].Cube->getBoundingBox();
       vector3df radius = box.MaxEdge - box.getCenter();

       //create collision response animator and attach it to the camera
	    ISceneNodeAnimator* RATRR = smgr->createCollisionResponseAnimator(
		selector, MainCamera, 
        radius,
		vector3df(0,0,0), 
		vector3df(0,0,0),
		.00005f  );
	    MainCamera->addAnimator(RATRR);
	   RATRR->drop();
And i try this:

Code: Select all

*ITriangleSelector* selector = smgr->createMetaTriangleSelector();
    OJ[wh].Cube->setTriangleSelector(selector);
    selector->drop();
Din't work :( :( :( :(

Can somebody tell me how to manage the jumping so that when i get on something other than the terrain i still could jump...

I can't really move on with my irrlicht learning before i learn how to jump because is one of the basic and needed thing on games.

(By the way my collision works perfect, is just the jumping)

HELP!
Last edited by Yellow_Yackets on Sun Nov 18, 2007 5:29 am, edited 1 time in total.
Y_Y
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi, You must put your triangle selector in the metaselector like this:
First define it:

Code: Select all

scene::IMetaTriangleSelector* meta
Then add each of your defined triangle selector to it. (So the metaselector will contain all the objects that you need to collide)

Code: Select all

meta->addTriangleSelector(selector); 
Once it's in there. When you define your Collision response Animator your define the MetaSelector instead of the selector. Like this:

Code: Select all

 //create collision response animator and attach it to the camera 
       ISceneNodeAnimator* RATRR = smgr->createCollisionResponseAnimator( 
      meta, MainCamera, 
        radius, 
      vector3df(0,0,0), 
      vector3df(0,0,0), 
      .00005f  ); 
Try this and tell us if it work.
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Post by Yellow_Yackets »

When i tried that, everything seemed to work perfect. It compiled well with no erros, but when i tried to run it, it throws a DON'T SEND error
like this:

Image

(I'm using Dev-C++ compiler.)

This is my code

Code: Select all

     
   IMetaTriangleSelector* metal;
     
	 ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox(OJ[wh].Cube);
    OJ[wh].Cube->setTriangleSelector(selector);
    selector->drop();
    
    metal->addTriangleSelector(selector);
    
       aabbox3d<f32> box = OJ[wh].Cube->getBoundingBox();
       vector3df radius = box.MaxEdge - box.getCenter();


	   ISceneNodeAnimator* RATRR = smgr->createCollisionResponseAnimator(
		metal, MainCamera, 
      radius,
		vector3df(0,0,0), 
		vector3df(0,0,0),
	   .00005f  );
	   MainCamera->addAnimator(RATRR);
	   RATRR->drop();

What am i missing?
Y_Y
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Christian skipped one very important step. Creating the meta selector. As your code is right now, you have a pointer to garbage that you are calling a meta selector. That won't work well.

You also need to add triangle selectors for each of your scene nodes to the meta selector. If you have 20 collidable boxes, you need to create selectors for each of them, and add those selectors to a meta selector.

Travis
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Post by Yellow_Yackets »

I have a FOR loop that adds to all the boxes the metaselector.

Now it RUNs very COOL but with the same problem.

CODE:

Code: Select all


IMetaTriangleSelector* meta;

ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox(OJ[wh].Cube);
OJ[wh].Cube->setTriangleSelector(selector);
selector->drop();

meta = smgr->createMetaTriangleSelector();
meta->addTriangleSelector(selector);

aabbox3d<f32> box = OJ[wh].Cube->getBoundingBox();
vector3df radius = box.MaxEdge - box.getCenter();

ISceneNodeAnimator* RATRR = smgr->createCollisionResponseAnimator(
meta, MainCamera,
radius,
vector3df(0,0,0),
vector3df(0,0,0),
.00005f  );
MainCamera->addAnimator(RATRR);
RATRR->drop();

Sorry i'm a little dumb on Errors like this (:oops:)

I try this also:

Code: Select all


if(KEY_SPACE)
{
  POS = MainCamera->getPosition(); 
  MainCamera->setPosition(vector3df(POS.X,POS.Y+99,POS.Z));
}

It jumps well but on the boxes it doesn't do anything. So i agree that my error has something to do with the collisions.
Can somebody give me a source sample of a FPS camera that jumps cool
so that i could get an idea on what i'm doing worng. OR is there a tutorial out there that talks about jumping?
Y_Y
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I have a FOR loop that adds to all the boxes the metaselector.
That isn't what your code is showing. You need to create just one meta selector and one collision response animator.

Code: Select all

// just do this once
IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector();
Then you need to add all of the selectors you create to that meta selector.

Code: Select all

for (u32 wh = 0; wh < N; ++wh)
{
    // create selector for each cube
    ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox(OJ[wh].Cube); 
    OJ[wh].Cube->setTriangleSelector(selector); 
    selector->drop(); 

    // add each selector to the meta selector
    meta->addTriangleSelector(selector);
}
Finally, create one collision animator

Code: Select all

ISceneNodeAnimator* RATRR = smgr->createCollisionResponseAnimator(meta, MainCamera, 5.f, vector3df(0,0,0), vector3df(0,0,0), .00005f); 
MainCamera->addAnimator(RATRR); 
RATRR->drop(); 
I posted code a while back that would generate triangle selectors for everything, and add them to a meta selector for you. The original post is in this thread. I later posted some code to only consider collisions with objects near the camera. You can see that here.

Here is a quick and dirty description of how this code works.
  1. ISceneManager_assignTriangleSelectors(ISceneManager* smgr, IFileSystem* ifs) generates collision information for every oct tree, mesh, animated mesh, terrain and cube scene node in the scene indicated by smgr. It does this by calling the next function. When this function returns, all of the collidable node types mentioned above will have their own triangle selector assigned.
  2. ISceneNode_assignTriangleSelectors(ISceneNode* node, ISceneManager* smgr, IFileSystem* ifs) assigns a triangle selector to the scene node node by calling the next function. It then calls itself recursively, so every node in the scene graph will have had this function called on itself.
  3. ISceneNode_assignTriangleSelector(ISceneNode* node, ISceneManager* smgr, IFileSystem* ifs) creates a triangle selector for the scene node node if possible. This code only works for oct tree, mesh, animated mesh, terrain and cube scene nodes. You could modify it to support other node types if you wanted, and you could modify it to create the selectors differently also [use a different lod for the terrain, or different parameters for the oct tree selector].
  4. ISceneManager_gatherTriangleSelectors(ISceneManager* smgr, IMetaTriangleSelector* meta) recursively gathers triangle selectors for all scene nodes that have them. All selectors are put into the meta selector. You could modify this function to filter which nodes are added or not. You could filter by name, id, address, or anything else if you felt the need.
  5. ISceneNode_gatherTriangleSelectors(ISceneNode* node, IMetaTriangleSelector* meta) adds the selector for node, if it has one, to meta, and then calls itself recursively on the children of node. This effectively gathers all selectors from node and all of its children/grandchildren/great-grand... into meta.
None of this code takes object position coherency into account, and the meta selector contains all of the selectors of all scene nodes. If your scene has many scene nodes, or your nodes have many triangles, then this primitive collision stuff probably won't work for you without some modification.

Travis
Yellow_Yackets
Posts: 29
Joined: Thu Oct 25, 2007 5:58 pm
Location: Florida
Contact:

Post by Yellow_Yackets »

It works perfectly now!!!!!
Thanks so much Vitek!!!!

I did exactly as you told me.

1. Create a meta collision
2. Assign the collisions to the selector
3. Then assign the meta to the selector

It works COOL....

Thanks again.
If somebody has the same problem and if at this point can't figure out
just ask here and I'll put a sample source code (if needed) because i think Vitek explanation is enough so i don't think i need to put the source).
Thanks
Y_Y
Post Reply