I'm making a swimming game and need help making a jump/move
The current code isn't quite giving me the right feel because I don't know how to use calculus here
(i presume that's what I need to do)
can I get a fix for my issue, please?
cls(12) x=60 y=60 function _update() y=y+.7 if btnp(2) then y=y-10 end --slapsh up if btnp(0) then x=x-3 end --splah back if btnp(1) then x=x+3 end --splash forward end function _draw() cls(12) circfill(x,y,4,7) end |
edited for online use
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bimg/pi/pi13.png)
I'm not quite sure what you are wanting to happen. I dont see any reason you would need calculus for jump physics.
Your code all makes sense to me and seems like it should execute correctly. I believe you could save some tokens by using the following syntax:
x-=3 |
Rather than:
x=x-3 |
That aside, your code all looks fine to me. Can you describe in more detail what you want to happen that is not currently happening?
EDIT: It is very possible that you want:
btn(0) --or whichever button |
rather than
btnp(0) |
In general, unless it is turn based movement, you probably want btn instead of btnp.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/25079/10_tumblr_a9803063c755e450aa8a4c37997fd9a1_96f72d5e_400.jpg)
I want a movement like a half jump
if you play the code or just look at it, you will see that it is jittery.
In a jump, the player would showdown them further it gets, so I believe I would need calculus of sorts here.
or maybe a parabola
if I used btn() then it would be smooth, but not a jump up or to the side
Sorry I haven't had a calculus class
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bimg/pi/pi13.png)
Lol, no calc needed. I promise.
If you are wanting to do a jump that slows down as you go up and then fall with increasing speed (up to your gravity max) you need a few things:
- You need to know if you are on the ground or not
- You need to know how long you have been in the air.
- You need to add velocity propelling you upward, rather than moving upward.
This will work as follows (this is a vague brief version as there are lots of ways to do this, but this should give you some ideas):
- You press jump, if you are on the ground it initiates a jump.
- It allows for a certain number of frames (miliseconds) worth of button presses on the jump, these presses add to a variable vy (velocity on the y axis).
- Each frame, two things happen: your jump presses push you upward (by subtracting your vy from your y) and gravity pulls you down by subtracting from your vy, eventually making it negative.
- When you hit the ground your vy = 0 and your onground = true
That was an off the cuff writing of it.
For better examples look into the following carts:
-
This one is more basic and a good start:
https://www.lexaloffle.com/bbs/?pid=28248&tid=27626 - This one adds lots of cool features:
https://www.lexaloffle.com/bbs/?pid=37402&tid=28793
Good luck!
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/25079/10_tumblr_a9803063c755e450aa8a4c37997fd9a1_96f72d5e_400.jpg)
Thanks, I never thought of using a velocity variable
I made what will work for my game
y=0 s=20 spe=1.7 function _update() y=y+s s=s/spe end function _draw() cls() print("it works!",50,y,7) end |
[Please log in to post a comment]