Computer Science Canada Having Trouble Implementing Gravity |
Author: | JakeTakeLake [ Mon Feb 11, 2013 5:08 pm ] | ||
Post subject: | Having Trouble Implementing Gravity | ||
What is it you are trying to achieve? realistic gravity What is the problem you are having? my sprite is jumping really fast, then coming back down slowly. i want it to be the same Describe what you have tried to solve this problem ive tried using tutorials but im still confused as to how to implement it into my code. i know how to make the sprite fall back down, but its the initial jump im confused about, i dont know how to make it smooth, without allowing them to only jump once when y=0 Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using 4.1.1 |
Author: | Insectoid [ Mon Feb 11, 2013 6:30 pm ] | ||||
Post subject: | RE:Having Trouble Implementing Gravity | ||||
This doesn't do what you think it does. Also, instead of having loads of sprites, just use one and change the picture on it with Sprite.ChangePic() or Sprite.Animate(). Also also, here's your actual problem:
If you hold W, the character will jump 40 pixels per frame. If you limit it so the character only jumps one time when W is pressed, your problem should be solved. |
Author: | JakeTakeLake [ Mon Feb 11, 2013 7:57 pm ] | ||
Post subject: | Re: RE:Having Trouble Implementing Gravity | ||
Insectoid @ Mon Feb 11, 2013 wrote: This doesn't do what you think it does. Also, instead of having loads of sprites, just use one and change the picture on it with Sprite.ChangePic() or Sprite.Animate(). Also also, here's your actual problem:
If you hold W, the character will jump 40 pixels per frame. If you limit it so the character only jumps one time when W is pressed, your problem should be solved. I did limit it. W only works when the sprite is at y=0. Thanks for the advice though. I'll start using sprite.changepic |
Author: | Insectoid [ Mon Feb 11, 2013 8:53 pm ] |
Post subject: | RE:Having Trouble Implementing Gravity |
Oh yes, I didn't see that. It's even in the code I linked. Lemme go slap myself in the face. Think about this. Your screen is 400 pixels high. Your initial jump velocity is 40 pixels, and gravity is 1.25. Your delay is 20ms. The character reaches the top of the screen in 11 frames, taking 1/5th of a second. It takes 32 frames for velocity to reach zero (the top of the jump) and 64 frames to hit the ground again, which takes 1.2 seconds. How do you fix this? Just tweak your gravity and jump velocity variables until it looks good. Otherwise, your code is just about fine. |
Author: | JakeTakeLake [ Tue Feb 12, 2013 4:16 pm ] | ||
Post subject: | Re: RE:Having Trouble Implementing Gravity | ||
Insectoid @ Mon Feb 11, 2013 wrote: Oh yes, I didn't see that. It's even in the code I linked. Lemme go slap myself in the face.
Think about this. Your screen is 400 pixels high. Your initial jump velocity is 40 pixels, and gravity is 1.25. Your delay is 20ms. The character reaches the top of the screen in 11 frames, taking 1/5th of a second. It takes 32 frames for velocity to reach zero (the top of the jump) and 64 frames to hit the ground again, which takes 1.2 seconds. How do you fix this? Just tweak your gravity and jump velocity variables until it looks good. Otherwise, your code is just about fine. What you're saying makes sense, but that's not what happens when I run it; it's hard to explain. I tried tweaking the variables, but the sprites disappear. I'm going to attach my new code (I took your advice with sprite.changepic) and I'll attach a zip file of my whole program, so you can see my problem.
|
Author: | Insectoid [ Tue Feb 12, 2013 4:44 pm ] | ||
Post subject: | RE:Having Trouble Implementing Gravity | ||
This is a problem. Can you figure out what it is? |
Author: | JakeTakeLake [ Tue Feb 12, 2013 5:11 pm ] | ||
Post subject: | Re: RE:Having Trouble Implementing Gravity | ||
Insectoid @ Tue Feb 12, 2013 wrote:
This is a problem. Can you figure out what it is? well i need it to round the the numbers because the coords are integers. i'm not sure why that would make the character jump up fast and fall back down slowly |
Author: | Dreadnought [ Tue Feb 12, 2013 7:03 pm ] |
Post subject: | Re: Having Trouble Implementing Gravity |
If interpreted in normal language the statements read "set position equal to velocity". Is that what they should read? |
Author: | JakeTakeLake [ Wed Feb 13, 2013 5:21 pm ] | ||
Post subject: | Re: RE:Having Trouble Implementing Gravity | ||
Insectoid @ Tue Feb 12, 2013 wrote:
This is a problem. Can you figure out what it is? Dreadnought @ Tue Feb 12, 2013 wrote: If interpreted in normal language the statements read "set position equal to velocity". Is that what they should read?
ohhh, i had to add it. thanks guys |