Page 1 of 1

Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 6:52 pm
by clepto
Hello!

With help from the wiki i manage to get my character to jump! but he can't jump while he is moving...try to press space while you hold "d"...

How can i make it jump while moving?

Also, as you can in the game, the character just passes through the crate...how can i make the crate to have a mass and be an obstacle to the character?

I attached the .love

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 9:25 pm
by raen79
Ok it's very simple, in love.update make a function called, for example, walking.speed and jumping speed linked to your velocity. So in love.update write

Code: Select all

walking.speed, jumping.speed=getLinearVelocity
Then in love.update, when you tell your character to jump, just do

Code: Select all

character:setLinearVelocity(walking.speed, -1000)
-1000 of course being your jumping speed.

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 9:30 pm
by Robin
clepto wrote:How can i make it jump while moving?
As far as I can see, that works.
clepto wrote:Also, as you can in the game, the character just passes through the crate...how can i make the crate to have a mass and be an obstacle to the character?
Note that you don't actually use the character's body. Get rid of objects.char.x and objects.char.y. Instead, use love.physics: for getting the character's position to draw it, use objects.char.body:getX and objects.char.body:getY. Instead of changing the x-position of the character directly in love.keypressed, use objects.char.body:applyLinearImpulse, and do the same for jumping.

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 9:37 pm
by clepto
i am telling my character to jump in love.keypressed so i added in the love.update the

Code: Select all

walking.speed, jumping.speed=getLinearVelocity
and in love.keypressed the

Code: Select all

character:setLinearVelocity(walking.speed, -1000)
but i guess i'm doing something wrong :P

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 9:40 pm
by clepto
Robin wrote: As far as I can see, that works.
i can move while jumping but i can't jump while moving :)
Robin wrote: Note that you don't actually use the character's body. Get rid of objects.char.x and objects.char.y. Instead, use love.physics: for getting the character's position to draw it, use objects.char.body:getX and objects.char.body:getY. Instead of changing the x-position of the character directly in love.keypressed, use objects.char.body:applyLinearImpulse, and do the same for jumping.
i'll make the changes and reply

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 9:47 pm
by clepto
@Robin

something like that?

Code: Select all

if key == "a" then
    objects.char.body:applyLinearImpulse( 10, 0 )
    char_direction = "left"
elseif key == "d" then
    objects.char.body:applyLinearImpulse( -10, 0 )
    char_direction = "right"
end

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 10:10 pm
by raen79
clepto you are doing something wrong, the getlinearvelocity, you have to do like character:getlinearvelocity, so if your character body is bloublou, it will be bloublou:getlinearvelocity. sorry ;)

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 10:18 pm
by clepto
raen79 wrote:clepto you are doing something wrong, the getlinearvelocity, you have to do like character:getlinearvelocity, so if your character body is bloublou, it will be bloublou:getlinearvelocity. sorry ;)
i know, i change that :crazy: there was something else...

@Robin i have a problem :crazy: can you look at the code? i attached the .love

Re: Jump while walking and how to make a box solid

Posted: Sat Jul 28, 2012 10:36 pm
by clepto
Everything looks good and working!! Thanks!

I attached the final .love in case someone want to see the code :)