[x][SOLVED]How to find out if A is on top of B node?

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
teamAlpha
Posts: 68
Joined: Sun Mar 08, 2009 4:14 pm

[x][SOLVED]How to find out if A is on top of B node?

Post by teamAlpha »

I'm trying to implement jumping in my game , but im a bit stuck while trying to find out if the player is on top of another object.

I've tried this:

Code: Select all

inline bool isOnTopOfNode(ISceneNode* a, ISceneNode* b) //is a on top of b??
{
	const vector3df& v0 = a->getPosition();
	const vector3df& v1 = b->getPosition();
	const vector3df& s0 = a->getScale();
	const vector3df& s1 = b->getScale();
	
	return
	 (  //we have a good chance to skip a few instructions...
		(v0.X  >= v1.X) && (v0.X <= v1.X + s1.X) //x ?
	  &&(v0.Z  >= v1.Z) && (v0.Z <= v1.Z + s1.Z) //z ?
	  &&(v0.Y  <= v1.Y) && (v0.Y >= v1.Y + s1.Y) //y ? a on top of b?
	  );
}
But it isn't working...

Any ideas why it isn't working? I have done this in 2d ...but in 3d it seems to be totally different ...
Last edited by teamAlpha on Sat May 02, 2009 9:35 am, edited 1 time in total.
Alpha::AppleBoy
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hmm, I'm not realy sure what you're doing there, but this makes me curious:

Code: Select all

(v0.Y  <= v1.Y) && (v0.Y >= v1.Y + s1.Y)
if v0.Y is less then or equal v1.Y then it can't be a also greater or equal v1.Y+s1.Y (also for X and Z) so it always will return false, or am I wrong ??? :shock:
maybe it must be:

Code: Select all

(v0.Y  >= v1.Y) && (v0.Y <= v1.Y + s1.Y)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post by Katsankat »

return (a->getPosition().Y > b->getPosition().Y);
teamAlpha
Posts: 68
Joined: Sun Mar 08, 2009 4:14 pm

Post by teamAlpha »

@Acki:
Thanks , but it isn't working :( .

I have even tried this :

Code: Select all

inline bool isOnTopOfNode(ISceneNode* a, ISceneNode* b) //is a on top of b??
{
//	a->updateAbsolutePosition();
	//b->updateAbsolutePosition();
	
	const aabbox3d<f32>&  ab = a->getTransformedBoundingBox();
	const vector3df& bp = b->getPosition();
	
		return (	bp.Y >= ab.MinEdge.Y &&// bp.Y <= ab.MaxEdge.Y && dont limit  Y
					bp.X >= ab.MinEdge.X && bp.X <= ab.MaxEdge.X &&
					bp.Z >= ab.MinEdge.Z && bp.Z <= ab.MaxEdge.Z);
}
But didn't worked either...

@Katsankat:
Yeah , i've tried that but my hero can jump any time ...there must be some bounding box collision
between the hero & the "walkable" nodes...
Alpha::AppleBoy
teamAlpha
Posts: 68
Joined: Sun Mar 08, 2009 4:14 pm

Post by teamAlpha »

I found it! , it worked with bounding box collision detection.

There was also a nasty bug in my loop , that looked like this:

Code: Select all


if( is on top of ( object array [ ... ] ) )
{
       if( it->classType != player classType)
       {
           ELEM_TYPE e = setNewElementToTrack(it->node)
           switch e
              case  WALKABLE:
                addFlags(EF_CANJUMP);
              break;
...
       }
       else
           setNewElementToTrack(NULL); // <--- THIS IS BAD
}
Alpha::AppleBoy
Post Reply