Page 1 of 1

Increasing height

Posted: Fri Aug 19, 2011 4:40 am
by Nubcake
Hi

This isn't an 'advanced game topic' but it is for game programming. I'm testing out this 2D game i'm creating and i've been stuck with this problem for hours now.
My player can jump in the game but every time he does , his y co-ordinate increases by about 10 pixels and i'm sure it's a simple error to you but not to me. Why is this happening?

Code: Select all

  If Player\jumping=1
   Sprite\row=13
   Sprite\frames=3
   Sprite\delayed=8
   Player\y-Player\jumph
   If Player\jumph<=0
     Player\jumph=0
   EndIf
   If Sprite\timer=32
     Sprite\timer=0
     Player\jumping=0  
     Player\jumph=0
     Player\jump=1
   EndIf
   If Player\jumph>=1
     Player\jump=0
   EndIf
   Debug Player\y
   If Player\jumph<=1 And Player\jump=1 
     Player\jumph+0.1
   Else
      Player\jumph-0.1
   EndIf

Re: Increasing height

Posted: Fri Aug 19, 2011 5:02 am
by netmaestro
It looks baffed but without the rest of the code it's impossible to say where.

Re: Increasing height

Posted: Fri Aug 19, 2011 5:06 am
by Nubcake
netmaestro wrote:It looks baffed but without the rest of the code it's impossible to say where.
The rest of the code is irrelevant , i know this , the problem lies in the one i submitted.

Re: Increasing height

Posted: Fri Aug 19, 2011 5:22 am
by netmaestro
Ok. Good luck with it.

Re: Increasing height

Posted: Fri Aug 19, 2011 11:40 am
by Kiffi
Nubcake wrote:
netmaestro wrote:It looks baffed but without the rest of the code it's impossible to say where.
The rest of the code is irrelevant , i know this , the problem lies in the one i submitted.
:lol:

Re: Increasing height

Posted: Fri Aug 19, 2011 12:01 pm
by bobobo
maybe it's easier to increase weight than height :mrgreen:
[sorry for that]

Re: Increasing height

Posted: Fri Aug 19, 2011 1:44 pm
by Zach
Are you comparing a float to an integer?

Maybe its causing a confusing rounding error for the CPU?


My guess would be try making the comparative (if its not already a float, do that too) 1.0 instead of just "1"

Re: Increasing height

Posted: Fri Aug 19, 2011 3:54 pm
by skywalk
Just put a loop around your logic section and print a 'Truth Table' based on all possibilities. :idea:

Re: Increasing height

Posted: Sun Aug 21, 2011 7:07 pm
by kenmo
I'm trying to make sense of your code...

. What is Player\jumping vs. Player\jump? They both seem to be integer 0/1 flags?

. Player\y is obvious (a float I hope), and Player\jumph seems to be your changing y-velocity (also a float)?

. \timer seems to stop your jump after exactly 32 frames? (instead of checking for collision with anything?)

. \row, \frames, and \delayed seem irrelevant to the jump physics... right? Are they drawing-related variables?

And what do you mean his y-coordinate increases 10 pixels... is it instantaneous, or does he smoothly jump upward but then stop after 10 pixels? If you could fit this code into a small running example, we could probably fix it in minutes.

(It also seems like you're overcomplicating it... typically my "Player" objects just have a y-coordinate, a y-velocity, and an in-air 0/1 flag. Of course there is also a gravity value, and a jump-button-pressed flag as well.)