Jump while walking and how to make a box solid

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
clepto
Prole
Posts: 35
Joined: Wed Jul 25, 2012 10:20 pm

Jump while walking and how to make a box solid

Post by clepto » Sat Jul 28, 2012 6:52 pm

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
Attachments
Blondie.love
(153.59 KiB) Downloaded 113 times

raen79
Citizen
Posts: 55
Joined: Sat Jul 21, 2012 11:58 pm

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

Post by raen79 » Sat Jul 28, 2012 9:25 pm

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.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin » Sat Jul 28, 2012 9:30 pm

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.
Help us help you: attach a .love.

clepto
Prole
Posts: 35
Joined: Wed Jul 25, 2012 10:20 pm

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

Post by clepto » Sat Jul 28, 2012 9:37 pm

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

clepto
Prole
Posts: 35
Joined: Wed Jul 25, 2012 10:20 pm

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

Post by clepto » Sat Jul 28, 2012 9:40 pm

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

clepto
Prole
Posts: 35
Joined: Wed Jul 25, 2012 10:20 pm

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

Post by clepto » Sat Jul 28, 2012 9:47 pm

@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

raen79
Citizen
Posts: 55
Joined: Sat Jul 21, 2012 11:58 pm

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

Post by raen79 » Sat Jul 28, 2012 10:10 pm

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 ;)

clepto
Prole
Posts: 35
Joined: Wed Jul 25, 2012 10:20 pm

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

Post by clepto » Sat Jul 28, 2012 10:18 pm

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
Attachments
Blondie.love
(149.47 KiB) Downloaded 89 times

clepto
Prole
Posts: 35
Joined: Wed Jul 25, 2012 10:20 pm

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

Post by clepto » Sat Jul 28, 2012 10:36 pm

Everything looks good and working!! Thanks!

I attached the final .love in case someone want to see the code :)
Attachments
Blondie.love
(149.51 KiB) Downloaded 110 times

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests