Events according to position

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
Mercyful
Posts: 8
Joined: Tue May 29, 2007 5:01 pm

Events according to position

Post by Mercyful »

Hi.

I got and question that may make you laugh, it's kinda dumb, super newbish.

Let's say When a character I move (a model) reach a position when it's need a node of a plataform (I'm thinking in a 3d plataform game like mario 64) moves foward or backward or do something, some change acording to the position of some node... how do I do?

I mean should I use a library? and AI library? wich one?

Should I do it in code, seems imposible, how do I suppose to know the exact position in wich I want a change happens (you know compare the x,y,z position of the back node and the x,y,z position of the node of the character and do the change)

Or maybe should I use a invisible cube and do something related to colision detection (like when a character collides with a invisible cube in the desired position do the change)?

The last seems better but it sounds a little bit "artificial".

Anyone knows something, should I go for the invisible cube?

Thank you very much, your help is really appreciated
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

What you're asking is a little confusing, but if you're talking about doing something when the player reaches a certain position I can think of a few solutions.

First of all, you could use the method you touched on with the invisible cube and create a box at the place where you want the event to happen, make it invisible then check for collision with the bounding box and do the event.

Another way you could do this (and probably the one I'd use, even if it isn't the best) would be to get the players x, y and z position (core::vector3df pos = node->getPosition()) and see if they are in the range for the area you want the event to happen in. This sort of thing could be written into a function pretty easy too, it might look something like this:

Code: Select all

bool isPlayerInPos(scene::ISceneNode playerNode, f32 minX, f32 maxX, f32 minY, f32 maxY, f32 minZ, f32 maxZ)
{
	core::vector3df pos = playerNode->getPosition();
	if ((pos.X > minX && pos.X < maxX) && (pos.Y > minY && pos.Y < maxY) && (pos.Z > minZ && pos.Z < maxZ))
	{
		return true;
	}
	else
	{
		return false;
	}
}
The only problem with that method is that to get the min and max values would take a bit (or maybe even alot) of trial and error. Hope that helps
Tell me what you cherish most. Give me the pleasure of taking it away.
Post Reply