Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualMilcho

Posted 25 January 2013 - 08:59 PM

combatcactus could you possibly put that in code format

Edit: i have kinda fixed it when i press space and enter the jumping statement my yVel goes from 0 to -120 and moves -120 y's but then it changes back to 0 so he dosent come down. Here is my updated code

if (jumping == true){myDot.yVel -= 120;if (myDot.yVel <= -240){myDot.yVel += 240;jumping = false;}}
Following each iteration through there, it looks to me like this:
1. yVel gets -= 120, and should now be -120 (assuming you set it to 0 when jumping)
2. yVel <= -240 evalutes to false, code moves to next loop
3. yVel gets -= 120, and should now be -240
4. yVel <= -240 evaluates to True - you enter the if statement
5. yVel gets += 240 - and now becomes 0
6. jumping is set to false, nothing more is executed in that part

If you want to set your velocity to some downward velocity (like positive 240) once it reaches a maximum, you should do two things:
a) make the statement yVel += 240 be just yVel = 240;
b) make the check yVel <= 240 be yVel < 240
- doing these will results in your yVel being -120, -240, 0 (after each execution of your loop).
Hope that helps, because I'm still not 100% clear on how you're using your yVel.

#1Milcho

Posted 25 January 2013 - 08:58 PM

combatcactus could you possibly put that in code format

 

Edit: i have kinda fixed it when i press space and enter the jumping statement my yVel goes from 0 to -120 and moves -120 y's  but then it changes back to 0 so he dosent come down. Here is my updated code



if (jumping == true)
{
myDot.yVel -= 120;
if (myDot.yVel <= -240)
{

myDot.yVel += 240;
jumping = false;
}
}

Following each iteration through there, it looks to me like this:

1. yVel gets -= 120, and should now be -120 (assuming you set it to 0 when jumping)

2. yVel <= -240 evalutes to false, code moves to next loop

3. yVel gets -= 120, and should now be -240

4. yVel <= -240 evaluates to True - you enter the if statement

5. yVel gets += 240 - and now becomes 0

6. jumping is set to false, nothing more is executed in that part

 

If you want to set your velocity to some downward velocity (like positive 240), you should do two things:

a) make the statement yVel += 240 be just yVel = 240;

b) make the check yVel <= 240 be yVel < 240 

- doing these will results in your yVel being -120, -240, 0 (after reach execution of your loop). 

Hope that helps, because I'm still not 100% clear on how you're using your yVel.


PARTNERS