Hi everybody!
I'm developing a platformer and I need to let the player to jump at three stages, so that it performs a low-, mid- and high-jump.
I've followed the platformer jumping tutorial that addresses my problem, in fact there is the "jetpack" system that works kinda well, and I can tweak it a bit so that the "jetpack" timer stops at a certain time (e.g. if jetpack timer is 0.5, 0 -> high-jump, 0.25 -> mid-jump, 0.05 -> low-jump) but my main concern is that the movement of the player, even if it's parabolic, it seems sometimes a bit laggy and unnatural... Or am I mad? xD
Anyway... is there some way to improve the jump animation? To me it seems like in the middle it stops a bit, and it seems more like it's flying than jumping!
[attached the tutorial file I've reproduce with tweaked gravity]
Incremental Jumping
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- msilvestro
- Prole
- Posts: 29
- Joined: Tue Feb 25, 2014 11:15 pm
- Location: Italy
- Contact:
Incremental Jumping
- Attachments
-
- platformer.love
- (12.13 KiB) Downloaded 96 times
- alberto_lara
- Party member
- Posts: 372
- Joined: Wed Oct 30, 2013 8:59 pm
Re: Incremental Jumping
Sure you can try changing the line 33 to this:
and the gravity variable to 1500 and check what happen.
Luck.
Code: Select all
player.y = player.y + player.y_velocity * dt*3 -- dt means we wont move at
Luck.
- msilvestro
- Prole
- Posts: 29
- Joined: Tue Feb 25, 2014 11:15 pm
- Location: Italy
- Contact:
Re: Incremental Jumping
Thanks for the answer! So it's as simple as this? I thought you needed more drastic change on that line equation!
Anyway, seems better... But can I ask a further question? Is that the best way to achieve an "incremental jumping"?
Anyway, seems better... But can I ask a further question? Is that the best way to achieve an "incremental jumping"?
Re: Incremental Jumping
The best way? Not sure. Give the same problem to different programmers and even if the goal is the same, the execution is likely to vary.
A timer is probably one of the simplest ways to do it - maybe I'm not savyy enough to think of other ways though.
My suggestion has little to do with the jetpack timer and more with coding style.
Many of the things you do in your game could be refactored to be clearer, shedding away with the comments - I know early optimization is bad but lack of any optimization is just as bad. Now, I'm not saying this is perfect and take it with a grain of salt as I tend to try to break things into as tiny pieces as I can but here is a small suggestion to get you started:
You might ask:
"If the end result is exactly the same, how is any of this useful?"
Breaking it down into smaller pieces, for me at least, gives a wider view of the program and allows me to more easily implement certain ideas. For example, now that you have an easy way to check to see if the player is touching the ground, you can come up with different ideas for different mechanics. Maybe something that bounces the player off the platform or inverts gravity or something else.
PS: If this is something you already know I apologize, I don't want to be pedantic but learning this would have helped me greatly when I just started.
A timer is probably one of the simplest ways to do it - maybe I'm not savyy enough to think of other ways though.
My suggestion has little to do with the jetpack timer and more with coding style.
Many of the things you do in your game could be refactored to be clearer, shedding away with the comments - I know early optimization is bad but lack of any optimization is just as bad. Now, I'm not saying this is perfect and take it with a grain of salt as I tend to try to break things into as tiny pieces as I can but here is a small suggestion to get you started:
Code: Select all
function player.isGrounded()
if player.y <= 0 then return true else return false end
end
function player.verticalStop() --bad function as it does more than one thing but for now it will suffice
player.y_velocity = 0
player.y = 0
player.jetpack_fuel = player.jetpack_fuel_max
end
function player.verticalAccel()
player.y_velocity = player.y_velocity + jump_height * (dt / player.jetpack_fuel_max)
end
function player.hasFuel()
if player.jetpack_fuel > 0 then return true else return false end
end
function player.decreaseFuel()
player.jetpack_fuel = player.jetpack_fuel - dt
end
function love.update(dt)
if player.hasFuel() and love.keyboard.isDown(" ") then player.decreaseFuel() player.verticalAccel() end
if player.isGrounded() == false then
player.y = player.y + player.y_velocity * dt -- dt means we wont move at different speeds if the game lags
player.y_velocity = player.y_velocity - gravity * dt
if player.isGrounded() then player.verticalStop() end
end
end
"If the end result is exactly the same, how is any of this useful?"
Breaking it down into smaller pieces, for me at least, gives a wider view of the program and allows me to more easily implement certain ideas. For example, now that you have an easy way to check to see if the player is touching the ground, you can come up with different ideas for different mechanics. Maybe something that bounces the player off the platform or inverts gravity or something else.
PS: If this is something you already know I apologize, I don't want to be pedantic but learning this would have helped me greatly when I just started.
- msilvestro
- Prole
- Posts: 29
- Joined: Tue Feb 25, 2014 11:15 pm
- Location: Italy
- Contact:
Re: Incremental Jumping
Thanks for the answer!OttoRobba wrote:The best way? Not sure. Give the same problem to different programmers and even if the goal is the same, the execution is likely to vary.
A timer is probably one of the simplest ways to do it - maybe I'm not savyy enough to think of other ways though.
My suggestion has little to do with the jetpack timer and more with coding style.
Many of the things you do in your game could be refactored to be clearer, shedding away with the comments - I know early optimization is bad but lack of any optimization is just as bad. Now, I'm not saying this is perfect and take it with a grain of salt as I tend to try to break things into as tiny pieces as I can but here is a small suggestion to get you started:
You might ask:Code: Select all
function player.isGrounded() if player.y <= 0 then return true else return false end end function player.verticalStop() --bad function as it does more than one thing but for now it will suffice player.y_velocity = 0 player.y = 0 player.jetpack_fuel = player.jetpack_fuel_max end function player.verticalAccel() player.y_velocity = player.y_velocity + jump_height * (dt / player.jetpack_fuel_max) end function player.hasFuel() if player.jetpack_fuel > 0 then return true else return false end end function player.decreaseFuel() player.jetpack_fuel = player.jetpack_fuel - dt end function love.update(dt) if player.hasFuel() and love.keyboard.isDown(" ") then player.decreaseFuel() player.verticalAccel() end if player.isGrounded() == false then player.y = player.y + player.y_velocity * dt -- dt means we wont move at different speeds if the game lags player.y_velocity = player.y_velocity - gravity * dt if player.isGrounded() then player.verticalStop() end end end
"If the end result is exactly the same, how is any of this useful?"
Breaking it down into smaller pieces, for me at least, gives a wider view of the program and allows me to more easily implement certain ideas. For example, now that you have an easy way to check to see if the player is touching the ground, you can come up with different ideas for different mechanics. Maybe something that bounces the player off the platform or inverts gravity or something else.
PS: If this is something you already know I apologize, I don't want to be pedantic but learning this would have helped me greatly when I just started.
Well, I'm actually a bit of a noob, even if in the past I wrote little applications. This is my first attempt to make something bigger, and effectively, I've learned by myself, by trial and error, that dividing the code is very useful. As you say, this way is simpler to clean the code and implement new features and locate bugs.
In fact the past week I worked mainly in "separating" the code to make everything more clear and polished. I've not yet achieved what I wanted about the jump, but this way the mechanics are more clear and it's more likely that I figure out what to do!
So thanks for pointing out this, makes me feel like I'm on the right way
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 6 guests