Page 1 of 1

Making a character walk around on uneven terrain

Posted: Fri Mar 22, 2013 11:51 pm
by Bannana97
I can't find any functions or methods to nail this the right way. I'm trying to make an easter game and having some problems - it is my first time making characters in-game.

Anyhow, my problems are:
  • The character is moving in the right direction, but I literally set velocity, so it isn't falling or walking up surfaces when necessary unless you stop walking
  • Character falls when climbing the high surfaces, while it should remain upright at all times.
I attached the love file. The file with the problem is \scenes\game\main.lua, line 225 is where the love.update is. Please, suggestions or tips would be appreciated. Thanks.
P.S. The pink-red box is the character: I'll be replacing it with an image soon. Just pretend, lol. :awesome:

Re: Making a character walk around on uneven terrain

Posted: Sat Mar 23, 2013 3:28 am
by notencore

Code: Select all

character["_.Object"].Body:setLinearVelocity(-100, 0)
You're setting the Y velocity to zero. Set it to a variable that contains the current force of gravity on the player. (If there's a platform under you it should be zero.)

Hope I could help, and if it doesn't work I apologize.

Re: Making a character walk around on uneven terrain

Posted: Sat Mar 23, 2013 7:03 am
by Bannana97
Yeah, that helps a bit. But I still would like to know if it's possible, and if so how, to force the block to remain upright, instead of falling down.

Re: Making a character walk around on uneven terrain

Posted: Sat Mar 23, 2013 8:26 am
by Robin
I think you could call this method on the player body right after you create it: Body:setFixedRotation

Re: Making a character walk around on uneven terrain

Posted: Sat Mar 23, 2013 3:09 pm
by Bannana97
Robin wrote:I think you could call this method on the player body right after you create it: Body:setFixedRotation
That or :setAngle(0) at a constant rate. Thanks for the help.