I do not know how to help with that, but maybe you could try to find a project on Scratch that has gravity, and then look at the code used in the game for it.
Offline
Gravity means objects get constantly accelerated - you need a speed variable that goes up by the same number whenever the sprite is not standing. When the sprite hits ground, set speed to 0.
Now to make your sprite move, change its position by speed every time:
forever if <not <touching [ground v]>> change [speed v] by (0.2) else set [speed v] to (0) end change y by (speed)
Last edited by roijac (2013-03-16 16:34:43)
Offline
roijac wrote:
Gravity means objects get constantly accelerated - you need a speed variable that goes up by the same number whenever the sprite is not standing. When the sprite hits ground, set speed to 0.
Now to make your sprite move, change its position by speed every time:forever if <not (touching [ground v]?)> change [speed v] by (0.2) else set [speed v] to (0) end change y by (speed)
Shouldn't you be changing speed by -0.2?
With regards,
ErnieParke
Last edited by ErnieParke (2013-03-17 15:01:38)
Offline
Thanks You guys really helped! It is working now! But i have another question, how do I make a sprite throw a gernade? I know the "when (button) clicked" stuff but what should i write to make it fly half-way across the screen?
Offline
fencer300 wrote:
Thanks You guys really helped! It is working now! But i have another question, how do I make a sprite throw a gernade? I know the "when (button) clicked" stuff but what should i write to make it fly half-way across the screen?
Well, there is a way. Just use this script:
when gf clicked set [X Velocity v] to (3)//Starting Upwards Speed set [Y Velocity v] to (3)//Starting Left/Right Speed repeat until (touching [floor v]?) change x by (X Velocity) change y by (Y Velocity) change [Y Velocity v] by (-0.25)//Gravity set [X Velocity v] to ((.98) * (X Velocity))//Optional end Explode!
Offline