[Solved] Help with basic platformer jumping

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
Fang86
Prole
Posts: 15
Joined: Fri Sep 25, 2015 2:03 am

[Solved] Help with basic platformer jumping

Post by Fang86 »

I just need help with basic platformer jumping for my game (newbie lua coder in general)
Code: http://pastebin.com/8FcwvMYJ
Beaver.png(Yes it's jsut a square): https://love2d.org/imgmirrur/pR1mzNo.png
Last edited by Fang86 on Sun Sep 27, 2015 9:32 pm, edited 1 time in total.
User avatar
redsled
Prole
Posts: 38
Joined: Wed Jun 04, 2014 6:33 am

Re: Help with basic platformer jumping

Post by redsled »

It'd help more if you attached the .love
Fang86
Prole
Posts: 15
Joined: Fri Sep 25, 2015 2:03 am

Re: Help with basic platformer jumping

Post by Fang86 »

redsled wrote:It'd help more if you attached the .love
Okay, and I have updated it a bit but here it is.
Attachments
BeaverBallRevenge.love
(145.12 KiB) Downloaded 172 times
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Help with basic platformer jumping

Post by bobbyjones »

That .love shows nothing for me, but the menu. I looked at the code and well it shows that your new to lua. First thing i would say is don't use loveframes for your GUIs. I saw you had another thread where you had an issue with them. I recommend just coding your own until you become more experienced. making a simple button is easy. Also you seem to set fullscreen every frame iirc. That isn't the best way to do things.
this bit:

Code: Select all

elseif love.keyboard.isDown("f3") and windowed == true and gamestate == "paused" or gamestate == "startmenu" then
    fullscreen = true
    windowed = false
elseif love.keyboard.isDown("f3") and fullscreen == true and gamestate == "paused" or gamestate == "startmenu" then
    windowed = true
    fullscreen = false
end
can become this:

Code: Select all

elseif love.keyboard.isDown("f3") and (gamestate == "paused" or gamestate == "startmenu") then
    fullscreen = not fullscreen
    love.window.setFullscreen(fullscreen)
end
The way that works is that it just toggles the value of fullscreen. not returns the opposite of the value. Also your conditions were a little messed up after a removed the windowed variable so i just had to add parenthesis.

To make a character jump you need y velocity, the jump impulse amount i guess(idk what to call it) and gravity

Code: Select all

local velY = 0
local y  = 300
local ground = 0
local jumpImpulse = 50
local gravity = 9.8 
once you have those you need to update your physics every frame

Code: Select all

y = y + velY*dt
velY = velY - gravity*dt

if y < ground then 
    y = ground
end
then you to get the key input

Code: Select all

function love.keypressed(key) 
    if key == " " then
        velY = velY + jumpImpluse
    end
end
That is very basic example of how to make something jump. I left some of it for you to have fun and discover lol. There is a few issues with that very basic example but im sure you will find them and fix them.
Fang86
Prole
Posts: 15
Joined: Fri Sep 25, 2015 2:03 am

Re: Help with basic platformer jumping

Post by Fang86 »

bobbyjones wrote:-Snip-
Thank you so much! :awesome: Also when I put the .love there I forgot to remove the start menu, I added a fully functional gui now
Post Reply

Who is online

Users browsing this forum: No registered users and 81 guests