Adding Collision to all new cubes

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
CodeDragon
Posts: 10
Joined: Sun Oct 17, 2010 8:45 am
Location: Belgium

Adding Collision to all new cubes

Post by CodeDragon »

I need help with a part of my game,
I'm making a game like MineCraft,
But I can fix my Collision for each block,
When I walk over it with an FPS camera I still can go true it.

I already read the Collision tutorial 4 times, and I know how to use it but It always gives errors, so I'm asking someone to help me.

I use this code (Check the end of the post) to draw the blocks when they are not existing,
I will redo it but first I need to fix the collision. (The Player is 2 Blocks High).

Is there a way todo this?

Code: Select all

{
	while(true)
	{
		//Handle Game//
		for (int I = 0; I < 500; I++)
		{
			if (Block[I].ID != NULL)
			{
				if (Block[I].Skin == NULL) // Create Objects if not exist.
				{
					Block[I].Skin = smgr->addCubeSceneNode();
					Block[I].Skin->setScale(core::vector3df(0.80f,0.80f,0.80f));
					Block[I].Skin->setPosition(Block[I].Position);
					Block[I].Skin->setMaterialTexture(0, BlockTex[Block[I].Type]);
					Block[I].Skin->setMaterialFlag(video::EMF_LIGHTING, false);

				}
			}
		}
		Sleep(10);
	}
	return 0;
}
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

I don't know that much about irrlicht's collision system since I mostly use Havok or bullet in my projects, but I do want to give you some pointers for making a minecraft-like game

First of all, it isn't a good idea to create a huge amount of cube scenenodes since you will get a high amount of drawcalls, with a big performance hit as a result
A solution to this would be to design and implement a manager so static geometry (probably most of the cubes) can be put in larger buffers, effectively reducing the amount of draw calls

Second, I wouldn't create the cubes the way you do know, it seems pretty wasteful to keep on iterating through a loop forever just for the purpose of checking if more cubes are needed

Maybe you should try to implement a simpler collision-based project before trying to achieve this

Good luck with the project ;)
CodeDragon
Posts: 10
Joined: Sun Oct 17, 2010 8:45 am
Location: Belgium

Post by CodeDragon »

Radikalizm wrote:I don't know that much about irrlicht's collision system since I mostly use Havok or bullet in my projects, but I do want to give you some pointers for making a minecraft-like game

First of all, it isn't a good idea to create a huge amount of cube scenenodes since you will get a high amount of drawcalls, with a big performance hit as a result
A solution to this would be to design and implement a manager so static geometry (probably most of the cubes) can be put in larger buffers, effectively reducing the amount of draw calls

Second, I wouldn't create the cubes the way you do know, it seems pretty wasteful to keep on iterating through a loop forever just for the purpose of checking if more cubes are needed

Maybe you should try to implement a simpler collision-based project before trying to achieve this

Good luck with the project ;)
Hmm..
I could store the cubes in a Array and draw them with a view distance,
Is that not a good idea?

But I still need collision. Because I can just walk true them and I already Tried a lot of things.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Each of your cube scene nodes is stored as data in a meshbuffer, the more meshbuffers you use (so more nodes) the more drawcalls you will need
you can solve this problem by putting all of your static geometry in a small amount of meshbuffers (I think you can find an implementation of this on these forums)
The problem however is that you still have to be able to edit these cubes when needed

I've played around with a minecraft clone written by someone here on the forum (can't remember the name of the author) which handled this problem very well, maybe you could talk to the author about how he handled it

EDIT:
about your collision problem, could you post a minimal code sample on how you create your triangle selector and how you set your collision response animator on your camera?
CodeDragon
Posts: 10
Joined: Sun Oct 17, 2010 8:45 am
Location: Belgium

Post by CodeDragon »

Radikalizm wrote:Each of your cube scene nodes is stored as data in a meshbuffer, the more meshbuffers you use (so more nodes) the more drawcalls you will need
you can solve this problem by putting all of your static geometry in a small amount of meshbuffers (I think you can find an implementation of this on these forums)
The problem however is that you still have to be able to edit these cubes when needed

I've played around with a minecraft clone written by someone here on the forum (can't remember the name of the author) which handled this problem very well, maybe you could talk to the author about how he handled it

EDIT:
about your collision problem, could you post a minimal code sample on how you create your triangle selector and how you set your collision response animator on your camera?
I did a loop, I just Grabbed the Selector like in the collision and then applied it to the camera, after the loop was finished I drop the selector.
Post Reply