This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-18 13:06:09

jono3814
New Scratcher
Registered: 2012-07-18
Posts: 17

JUMPING with gravity in mind.

how would you make a sprite jump with gravity in play? without it landing on a obsticle all the time. so you can walk then jump (realistically) using space bar and carry on walking ?

Offline

 

#2 2012-07-18 13:13:12

silvershine
Scratcher
Registered: 2010-11-21
Posts: 500+

Re: JUMPING with gravity in mind.

Hello!

There's a really good platform base that RHY posted a while ago. If you want, you can download it and take a look at the gravity scripts. Because it's a base for a project, it's perfectly alright if you add your own sprites and levels and upload that!

Here it is: (link)

Offline

 

#3 2012-07-18 13:15:43

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: JUMPING with gravity in mind.

jono3814 wrote:

how would you make a sprite jump with gravity in play? without it landing on a obsticle all the time. so you can walk then jump (realistically) using space bar and carry on walking ?

Try something like this:

when gf clicked
set [gravity v] to (-0.2) //or whatever you want
set x to (0) //or your start position
set y to (0) //^^
set [Velocity.X v] to (0)
set [Velocity.Y v] to (0) //This is your speed basically
forever
change x by (Velocity.X)
change y by (Velocity.Y)
if <touching [level v]?> //or whatever sensing system you're using
change y by ((Velocity.Y) * (-1))
set [Velocity.Y v] to (0)
else
change [Velocity.Y v] by (gravity)
end
set [Velocity.X v] to ((Velocity.X)*(0.99))
set [Velocity.Y v] to ((Velocity.Y)*(0.99))
Hope that helps!


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#4 2012-07-18 14:41:39

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: JUMPING with gravity in mind.

Simplest method.

when gf clicked
forever
 if <touching [ground v]?> //Your ground.
  set [yvel v] to [0]
  if <key [up arrow v] pressed?>
   set [yvel v] to [5] //You can adjust this number.
   change y by (5) //Same number as above.
  end
 else
  change [yvel v] by (-0.1)
  change y by (yvel)
 end
end

Last edited by SciTecCf (2012-07-18 14:42:01)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#5 2012-07-18 15:13:37

giamsan
Scratcher
Registered: 2012-07-13
Posts: 23

Re: JUMPING with gravity in mind.

there are tutorials on youtube that are quite good and there is one that also makes it speed up as it gets closer to the ground.

Offline

 

Board footer