Page 1 of 1
[Solved] Help with basic platformer jumping
Posted: Fri Sep 25, 2015 2:37 am
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
Re: Help with basic platformer jumping
Posted: Sat Sep 26, 2015 5:50 am
by redsled
It'd help more if you attached the .love
Re: Help with basic platformer jumping
Posted: Sat Sep 26, 2015 3:08 pm
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.
Re: Help with basic platformer jumping
Posted: Sun Sep 27, 2015 8:22 pm
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.
Re: Help with basic platformer jumping
Posted: Sun Sep 27, 2015 8:56 pm
by Fang86
bobbyjones wrote:-Snip-
Thank you so much!
Also when I put the .love there I forgot to remove the start menu, I added a fully functional gui now