Qbasicnews.com

Full Version: Jumping Jack Problem!!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
welll...
I wanted to make a mario-like game
but can anyone tell me how do i make that character jump diagonally??
or do i have to use some equations of parabola?
The way to do it is having a gravity engine and working with horizontal and vertical movement separately.

Establish x, y, vx, vy, (velocities) a (horizontal acceleration) and g (gravity) and use those cinematics equations, those from physics.
Cinematics equations of physics??!??!?!????????

u mean parabola??
I think he ment sinemactics.. cause it sounds like sinus.. prolly off, never heard the term.. =P

The way I'd do it, is, I would take: cheat.... I'd give the sprite gravity, that holds him to the ground.... then alow it to jump up with enough power to temperaly brake the hold, then drop him back down.... But while he is alowed to jump up and down, alow side to side movents in the air....

Thus, when he jumps up, and your holding over, he'll jump in an arch....

You prolly can sit around, and figure up projectiles: lanch speed, angle, vertical accel, horizontal accel, etc.... But the first method in my post would be more of and "arcade" feel like mario had.... I think.....

Hope that helps some.... :winkwink:
It's Kinematics, BTW.
up key. left/right key. jump.

my work here is done.
Quote:It's Kinematics, BTW.
Oops ... That term I have heard before... the C just threw me off... -_- ... I still think that's a bit too detialed for an arcade-style game.... Unless you are making a simulater.... =) ..

Though, more info if you are interested: http://en.wikipedia.org/wiki/Kinematics

:winkwink:
Well... yes..Kinematics include That parabola equations...

And i tried it and it works perfectly..

and hey dio, What do u mean by that

Dio Wrote:

Quote:up key. left/right key. jump.

my work here is done.

???
do u mean to say that i should store up,right/left keypresses in
INKEY$ buffer???
I repeat: my work here is done.
Yeah, physics.

Horizontal movement:

In each cycle:

Code:
x = x + vx

If <left key pressed> Then
   vx = vx - a
Else If <right key pressed> Then
   vx = vx + a
Else
   If vx > 0 Then
      vx = vx - f
   Else
      vx = vx + f
   End If
End If

If <collision with map> Then
   <track back to furthest possible location>
End If

Where x is your horizontal coordinate, vx is your horizontal velocity, a is your horizontal acceleration, f is your horizontal friction.

Vertical movement:

In each cycle:

Code:
y = y + vy
vy = vy + g

If <jump key pressed> Then
   If <player standing on a platform Then
      vy = vy - j
   End If
End if

If <collision> Then
   <track back to furthest possible location>
End If

Where y is your vertical coordinate, vy is your vertical velocity, g is gravity, j is jump strength.

It's not hard at all once you understand the equations. This needs decimal variables to work, keep that in mind. Better than using floats would be using some kind of fixed point math, something like using X bits for the decimal part and Y bits for the real part. For example, if you use 16 bits integers and have pixel coordinates in the range of 0-320 (for example), you could multiply/divide by 64 to gain six digits after the decimal point, thus gaining a precision of 1/64 of a pixel.

Code:
xOnScreen = x \ 64
x = xOnScreen * 64

This means that to actually advance one pixel you have to add 64, not 1. But that means that you can get smooth movement 'cause everytime you add 1 to x you are in fact "advancing 1/64 of a pixel".

A good understanding in kinematics helps a tad. Basicly you are using the accelerated movement equations:

Code:
v = v0 + a * t
s = s0 + v0*t + 1/2 * a * t^2

I was planning on writing a tutorial for this on QBE, I have to find time to do it.
Pages: 1 2