Re: How can I make my character jump?
Posted: Sun Apr 22, 2012 5:12 pm
You don't need to write "require 'conf'", because LOVE automatically requires it before requiring main.lua
Code: Select all
function love.conf(t)
t.version = "0.8.0" -- The LÖVE version this game was made for (string)
end
Besides the problems and good suggestions that robin pointed (hovering bug/colliding_plataform) notice that since you are not drawing a real floor you don't see an eventual problem. When you comparing "player.y > 400" you checking the top of your head with something. So unless that 400 value is the same as "floor - player.heigth" actually you should being compare something like "player.y + player.height > 400" that in this case player.height should be 40.Puzzlem00n wrote:STOP THE PRESSES! I think I have a better fix for this.
That way you don't have to mess with booleans, which I prefer to avoid.Code: Select all
function love.load() player = { x = 280, y = 380, ySpeed = 0, -- the Speed we'll add to the Y movement gravSecond = 1.5 -- gravity amount } end function love.update(dt) frame = dt * 30 -- I do this just because I think better this way player.ySpeed = player.ySpeed + player.gravSecond * frame -- We add gravity to the ySpeed player.y = player.y + player.ySpeed * frame -- We add ySpeed to the player's y position if player.y > 400 then -- Are we on the ground? player.y = player.y - player.ySpeed * frame -- If we are, We undo that moving down player.ySpeed = 0 -- The ySpeed is reset end if love.keyboard.isDown("up") and player.ySpeed == 0 then -- Should we be jumping, and can we? --This works because the ySpeed is only zero when we aren't already jumping. player.ySpeed = -20 -- Make us add a negative, to move up end end function love.draw() love.graphics.rectangle("fill", player.x, player.y, 40, 40) -- Draw it! end
Yeah, I know... I figured that was sort of obvious. (no offense. ) It's just, you know, not necessary until there's actual ground. I have in fact made a full platform engine from this, and I myself didn't add it until then.coffee wrote:Besides the problems and good suggestions that robin pointed (hovering bug/colliding_plataform) notice that since you are not drawing a real floor you don't see an eventual problem. When you comparing "player.y > 400" you checking the top of your head with something. So unless that 400 value is the same as "floor - player.heigth" actually you should being compare something like "player.y + player.height > 400" that in this case player.height should be 40.Puzzlem00n wrote:STOP THE PRESSES! I think I have a better fix for this.
That way you don't have to mess with booleans, which I prefer to avoid.Code: Select all
function love.load() player = { x = 280, y = 380, ySpeed = 0, -- the Speed we'll add to the Y movement gravSecond = 1.5 -- gravity amount } end function love.update(dt) frame = dt * 30 -- I do this just because I think better this way player.ySpeed = player.ySpeed + player.gravSecond * frame -- We add gravity to the ySpeed player.y = player.y + player.ySpeed * frame -- We add ySpeed to the player's y position if player.y > 400 then -- Are we on the ground? player.y = player.y - player.ySpeed * frame -- If we are, We undo that moving down player.ySpeed = 0 -- The ySpeed is reset end if love.keyboard.isDown("up") and player.ySpeed == 0 then -- Should we be jumping, and can we? --This works because the ySpeed is only zero when we aren't already jumping. player.ySpeed = -20 -- Make us add a negative, to move up end end function love.draw() love.graphics.rectangle("fill", player.x, player.y, 40, 40) -- Draw it! end
It's not actually a question if is obvious for you but that BEANSFTW undestand all things to how correctly make his char jump. Don't worry I know your let's say "full" platform engine (viewtopic.php?f=4&t=8740) from what you keep copy/past pieces of it in various threads. However I'm afraid it don't erase some problems on it like your "boolean" fear and worst have serious problems in bound detection/movement. So, sometimes either fails not touching correctly sideways or ends stuck in walls jumping. I think would be nice you refine and fix it first before help people (that is always good you want it to do) with pieces of it. No offense I hope.Puzzlem00n wrote: Yeah, I know... I figured that was sort of obvious. (no offense. ) It's just, you know, not necessary until there's actual ground. I have in fact made a full platform engine from this, and I myself didn't add it until then.
P.S. Is Beans is still even on this thread???
That's the one thing I don't completely see the error of. How does doing it the way I do make a problem? As far as I can tell, it's not really much of an issue unless you make the ySpeed possibly equal to zero in the air.coffee wrote:However I'm afraid it don't erase some problems on it like your "boolean" fear...
A quick warning. Besides your help here, you for example post a "full" platform code (but a stripped edition of your engine whitout lava and exit) here (viewtopic.php?f=4&t=8922) that you didn't tested first for sure. With the lack of declaration of a value in player.y you get obvious error screen when operating it in update. Since no one noticed, protested or posted after you can still get there and correct it witouth an "edited" mark.Puzzlem00n wrote:Oh, wow, I do use it in a lot of places, don't I? Yes, I suppose I shouldn't call it full, and it could use some improvements. I never really polished it, because, you know, I hadn't planned on using it to help people, it just turned out that way.
Already told you but here some shots illustratting the problems:coffee wrote:I've never gotten stuck in a wall, though, so what kind of serious problems are you getting?
You right it's not an "error" itself of course, but a style (or lack of it) that leads to problems or complicates our code. But you can bet that a lot of serious coders should see our/theirs own bad code as human "errors"!Puzzlem00n wrote:That's the one thing I don't completely see the error of. How does doing it the way I do make a problem? As far as I can tell, it's not really much of an issue unless you make the ySpeed possibly equal to zero in the air.