I want to do a platform game and I need gravity but all this stuff about volocity gets me confused. Can any one explain it?
Offline
Gravity is simply what it is in real-life; it makes a player fall.
Now onto velocity; velocity just stores a sprite's speed in a certain direction. So XVelocity woud be an sprite's speed left/right, and YVelocity would by a sprite's speed up/down. It's often used to help make movement in games more realistic.
Anyway, I hope that this helps! Also, hello Scratchmad525 and welcome to Scratch! I wish you good luck learning how to create a game!
Offline
Velocity is also "simply what it is in real life"; a constant change of the position of an object, by a certain amount, in a certain unit (pixels), in a certain direction.
What platformer games do, is merely simulate the physical concepts of gravity and velocity. The approach usually taken to simulate the latter, is to have both "X velocity" and "Y velocity" variables, that will be changed constantly by the game; then sprites can change their position by this amount at a constant rate.
I recommend you read a bit about simulating gravity using a "velocity" variable in the Scratch Wiki. The Wiki also has many articles about scrollers for you to read c:
Last edited by technoguyx (2012-12-14 19:37:59)
Offline
Thanks everyone
Offline
My usage of velocity would be like this.
Eg
A sprite is at x0 y0, then it changes it's x velocity by 1 everytime the key right is pressed, meaning, everytime the key right is pressed, the sprite moves faster, to avoid this you have to set it to itself multiplied by a positive number closer to 1 to make a smooth movement (eg 0.9) and a positive number further to 1 to make a rough movement (eg 0.5). The same applies to moving left but all change variable blocks by, must be negative. Here is an example:
when gf clicked set [xv v] to [0] set [yv v] to [0] set x to (xv) set y to (yv) forever change x by (xv) change y by (yv) if <key [left arrow v] pressed?> change [xv v] by [-1] end if <key [right arrow v] pressed?> change [xv v] by [1] end if <touching colour [#903d3d]?>// touching the colour of the ground you want the sprite to touch set [yv v] to [1] if <key [up arrow v] pressed?> set [yv v] to [10] end end change [yv v] by [-0.5] set [xv v] to ((xv)*[0.9]) end
Last edited by Ideas (2012-12-21 08:16:30)
Offline