How do you make gravity or make a character jump?
Offline
IllusionOptics wrote:
How do you make gravity or make a character jump?
Here's a simple script:
when gf clicked forever if (up arrow pressed AND touching ground colour ) repeat (?) change y by (speed) end repeat until ( touching ground colour) change y by ( - speed ) end else if (not touching ground colour) repeat until ( touching ground colour) change y by ( - speed )
Last edited by CopperHawk (2012-11-25 01:23:26)
Offline
Check out my Gravity tutorial!
http://scratch.mit.edu/projects/AngryCamel/2932671
Offline
CopperHawk wrote:
IllusionOptics wrote:
How do you make gravity or make a character jump?
Here's a simple script:
when gf clicked forever if <<key [up v] pressed?> and <touching color (ground color)?>> repeat (x) change y by (speed) end repeat until <touching color (ground color)?> change y by ((0) - (speed)) end else if <not <touching color (ground color)?>> repeat until <touching color (ground color)?> change y by ((0)-(speed))
Fixed.
Offline
mathfreak231 wrote:
CopperHawk wrote:
IllusionOptics wrote:
How do you make gravity or make a character jump?
Here's a simple script:
when gf clicked forever if <<key [up v] pressed?> and <touching color (ground color)?>> repeat (x) change y by (speed) end repeat until <touching color (ground color)?> change y by ((0) - (speed)) end else if <not <touching color (ground color)?>> repeat until <touching color (ground color)?> change y by ((0)-(speed))Fixed.
Thanks. XD
Offline
CopperHawk wrote:
mathfreak231 wrote:
CopperHawk wrote:
Here's a simple script:
when gf clicked forever if <<key [up v] pressed?> and <touching color (ground color)?>> repeat (x) change y by (speed) end repeat until <touching color (ground color)?> change y by ((0) - (speed)) end else if <not <touching color (ground color)?>> repeat until <touching color (ground color)?> change y by ((0)-(speed))Fixed.
Thanks. XD
how do you make a character jump while going right/left and the jump continues to bring it in the direction while jumping?
-Illusion
Last edited by IllusionOptics (2012-12-16 09:33:09)
Offline
IllusionOptics wrote:
how do you make a character jump while going right/left and the jump continues to bring it in the direction while jumping?
-Illusion
X and Y positions are generally independent of each other, so there shouldn't be much interference between jumping and moving right and left. Placing the right and left motion in a separate script seems appropriate for this kind of jumping script.
Alternately, to put right/left motion into the same script, you need to see why you are unable to just place some right/left code in. The reason why you can't move right and left with coding in the above script is because the repeat block shuts out the rest of the logic of the script while it is repeating. You can copy/paste your right/left section of the script into the repeat block and put a second one outside the repeat block. That way it will work whether you are jumping or not.
Last edited by Kileymeister (2012-12-17 18:33:45)
Offline
Kileymeister wrote:
IllusionOptics wrote:
how do you make a character jump while going right/left and the jump continues to bring it in the direction while jumping?
-IllusionX and Y positions are generally independent of each other, so there shouldn't be much interference between jumping and moving right and left. Placing the right and left motion in a separate script seems appropriate for this kind of jumping script.
Alternately, to put right/left motion into the same script, you need to see why you are unable to just place some right/left code in. The reason why you can't move right and left with coding in the above script is because the repeat block shuts out the rest of the logic of the script while it is repeating. You can copy/paste your right/left section of the script into the repeat block and put a second one outside the repeat block. That way it will work whether you are jumping or not.
Question: While jumping, I cannot go left/right while in the air. I tried out the scripts above and I couldn't do that. Anything wrong, maybe?
Offline
IllusionOptics wrote:
Kileymeister wrote:
IllusionOptics wrote:
how do you make a character jump while going right/left and the jump continues to bring it in the direction while jumping?
-IllusionX and Y positions are generally independent of each other, so there shouldn't be much interference between jumping and moving right and left. Placing the right and left motion in a separate script seems appropriate for this kind of jumping script.
Alternately, to put right/left motion into the same script, you need to see why you are unable to just place some right/left code in. The reason why you can't move right and left with coding in the above script is because the repeat block shuts out the rest of the logic of the script while it is repeating. You can copy/paste your right/left section of the script into the repeat block and put a second one outside the repeat block. That way it will work whether you are jumping or not.Question: While jumping, I cannot go left/right while in the air. I tried out the scripts above and I couldn't do that. Anything wrong, maybe?
try placing the right/left script in its own script if you haven't done so already.
the only reason you might need to combine them is for saving scripts as in 1sprite 1script projects, which is usually not the main goal, but rather to make a working game
Offline