Log In  

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

P#43214 2017-08-13 14:29 ( Edited 2017-08-13 20:07)

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.

P#43216 2017-08-13 14:57 ( Edited 2017-08-13 19:00)

@sloum

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

P#43217 2017-08-13 15:26 ( Edited 2017-08-13 19:28)

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:

  1. You need to know if you are on the ground or not
  2. You need to know how long you have been in the air.
  3. 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):

  1. You press jump, if you are on the ground it initiates a jump.
  2. 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).
  3. 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.
  4. 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:

  1. This one is more basic and a good start:
    https://www.lexaloffle.com/bbs/?pid=28248&tid=27626

  2. This one adds lots of cool features:
    https://www.lexaloffle.com/bbs/?pid=37402&tid=28793

Good luck!

P#43220 2017-08-13 15:49 ( Edited 2017-08-13 19:49)

@sloum

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
P#43222 2017-08-13 16:07 ( Edited 2017-08-13 20:07)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 11:10:01 | 0.013s | Q:15