Moving character in 2.5D platformer

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Moving character in 2.5D platformer

Post by 3DModelerMan »

Does anyone know of a good technique to make a player character move along the correct path? I had the level be where it just goes straight to the right. Now I'm redesigning it and it goes to the right then turns and goes back to normal then loops around (and there will be more of this later). I can't just move straight along the X-axis like I normally do.
Thanks :D .
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

i don't really understand... :?:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

yeah not sure i understand either... maybe a picture would help?

what's your control scheme? it seems that you're going to be changing the axis the player moves along, will the controls change too?
Image Image Image
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Platforms

Post by 3DModelerMan »

It's a side scroller rendered in 3D like Kirby 64.
This is the path that he follows now, the red line shows his path and the black is platforms.
Image
And this is what it should be.
Image
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

oh... he means something like this: http://www.youtube.com/watch?v=AlsH_AH7CDs

that's the thing that i've been always wondering as well.
trivtn
Posts: 132
Joined: Tue Jan 17, 2006 12:30 pm
Location: Viet Nam
Contact:

Post by trivtn »

I think Starcraft game is good example all he want.
There's something is fantastic, there's nothing is absolute.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Might have to use some kind of waypoint graph to follow
Image Image Image
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

The way I've saw this coded before was as a line of node. Every point on the movement axis is either a node or in-between 2 nodes. You then only have to keep track of progression on said line to know your orientation. Look at heightmap, it'll give you some help.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Hmmm

Post by 3DModelerMan »

Yeah that could be a good way. Would a trail of flat planes work so that I could move the character forward and the rotation of the character changes depending on the normal the raycast hit? Or is that inefficient?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

I tried

Post by 3DModelerMan »

I tried to figure out an implementation for this.

Code: Select all

if ( !path.empty() )
  {
   //Store Pingy's bounding box.
   aabbox3df pingyBB = mRenderMesh->getTransformedBoundingBox();
   vector3df lastPoint;
   vector3df currPoint;
   vector3df nextPoint;
   //Loop over list
   for (int i=0; i<path.size(); ++i)
   {
    //Check if point has been reached.
    if ( pingyBB.isPointInside( path[i]->getPosition() ) );
    {
     //Set the path points.
     if ( path[i-1] != NULL )
     lastPoint = path[i-1]->getPosition();
     if ( path[i] != NULL )
     currPoint = path[i]->getPosition();
     if ( path[i+1] != NULL )
     nextPoint = path[i+1]->getPosition();
     //Check for what side pingy is on.
     //=============================================
     if ( mRenderMesh->getPosition().X < path[i]->getPosition().X )
     {
      //Set new rotation.
      //=============================================
      vector3df toNext = mRenderMesh->getPosition()-nextPoint;
      vector3df newRot = toNext.getHorizontalAngle();
      mRenderMesh->setRotation(newRot);//(Or the controller empty)
      //=============================================
     }
     else
     {
      //Set new rotation.
      //=============================================
      vector3df toLast = mRenderMesh->getPosition()-lastPoint;
      vector3df newRot = toLast.getHorizontalAngle();
      mRenderMesh->setRotation(newRot);//(Or the controller empty)
      //=============================================
     }
    }
   }
  }
But for some reason it crashes.
I have the first and second scene nodes put in the path already.
What am I doing wrong?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Or maybe...

Post by 3DModelerMan »

Or maybe this psuedocode has the basic idea?

Code: Select all

if ( pointIsInBox(playerBB) )
{
 if ( playerPos > pointPos[i] && playerPos < pointPos[i+1] )
 //rotate.

 //do other side.
}
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

you could add invisible nodes at every turn and make the player face the direction of it for example:

Image

you can use this function to get the angle between 2 points:

Code: Select all

double PointDirection(double x1, double y1, double x2, double y2){
	double angle=0;	
	angle=(atan2(x1-x2,y1-y2)*180)/3.14;
	return angle;
}
each node has the location of the next one so when the player reaches it, he gets the position of the next one, and faces that direction
Image
Josie
Posts: 44
Joined: Sat Jul 25, 2009 4:08 am
Location: Griffin, Georgia, US
Contact:

Post by Josie »

Grumpymonkey is right. The best way I can think of is a node-based path. You can use splines if you want it to be extremely smooth. Interpolating between the points makes everything blend together. The camera will of course be rotated to face the current point between two nodes where the character is, and the location of the camera can be determined using cross products.
Post Reply