Page 1 of 1

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

Posted: Fri May 01, 2009 10:34 pm
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 ...

Posted: Sat May 02, 2009 2:27 am
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)

Posted: Sat May 02, 2009 3:40 am
by Katsankat
return (a->getPosition().Y > b->getPosition().Y);

Posted: Sat May 02, 2009 9:16 am
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...

Posted: Sat May 02, 2009 9:34 am
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
}