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

#1 2012-03-16 05:18:26

alexthechicken
New Scratcher
Registered: 2012-03-16
Posts: 1

How to make gravity?

Please help, not clear!

Offline

 

#2 2012-03-16 06:04:52

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: How to make gravity?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3 2012-03-16 07:09:33

hokkaidoandme
New Scratcher
Registered: 2012-03-09
Posts: 7

Re: How to make gravity?

no one likes answering gravity questions properly...... with sceen shots..... same happened to me,,,,,

Offline

 

#4 2012-03-16 07:16:11

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: How to make gravity?

Fine, I'll answer it "properly". What sort of gravity? Like Earth-and-moon or person-and-Earth?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5 2012-03-16 10:03:03

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: How to make gravity?

Normally it's like this:

when gf clicked
set [yvel v] to [0]
forever
if <touching [ground v]?>
if <(0?) = [1]> //only necessary if you have jumping.
set [yvel v] to [0] //or 1 if you're not using the nice slope physics.
end
set [0? v] to [0] //again only if there's jumping involved 
else
change [yvel v] by [-1] //or whatever
set [0? v] to [1]
If you set yvel to 1, you might not need "0?".
To jump;
if <<touching [ground v]?> and <key [up arrow v] pressed?>> //or whatever controls
set [yvel v] to (Jumpspeed)

Last edited by Splodgey (2012-03-16 10:03:45)

Offline

 

#6 2012-03-16 12:01:55

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: How to make gravity?

Here's a formula I like to use for gravity and friction:

when gf clicked
forever
 if <key [right arrow v] pressed?>
  change [xvel v] by (1)
 end
 if <key [left arrow v] pressed?>
  change [xvel v] by (-1)
 end
 set [xvel v] to ((xvel) * (.87))
 change x by (xvel)
 if <touching [level v]?>
  change x by ((0)-(xvel))
  set [xvel v] to (0)
 end
 if <key [up arrow v] pressed?>
  change y by (-1)
  if <touching [level v]?>
   set [yvel v] to (10)
  end
  change y by (1)
 end
 if <(yvel) < [3]>
  change y by (-1)
  if <not<touching [level v]?>>
   change (yvel) by (-1)
  end
  change [yvel v] by (1)
 end
 set [yvel v] to ((yvel) * (0.9))
 change y by (yvel)
 if <touching [level v]?>
  change y by ((0) - (yvel))
  set [yvel v] to (0)
 end
end

Last edited by chanmanpartyman (2012-03-18 13:07:43)

Offline

 

#7 2012-03-16 12:58:23

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: How to make gravity?

chanmanpartyman wrote:

Here's a formula I like to use for gravity and friction:

when gf clicked
forever
 if <key [right arrow v] pressed?>
  change [xvel v] by (1)
 end
 if <key [left arrow v] pressed?>
  change [xvel v] by (-1)
 end
 set [xvel v] to ((xvel) * (.87))
 change x by (xvel)
 if <touching [level v]?>
  change x by ((0)-(xvel))
  set [xvel v] to (0)
 end
 if <key [up arrow v] pressed?>
  change y by (-1)
  if <touching [level v]?>
   set [yvel v] to (10)
  end
  change y by (1)
 end
 if <(yvel) < [3]>
  change y by (-1)
  if <not<touching [level v]?>>
   change [yvel v] by (-1)
  end
  change [yvel v] by (1)
 end
 set [yvel v] to ((yvel) * (0.9))
 change y by (yvel)
 if <touching [level v]?>
  change y by ((0) - (yvel))
  set [yvel v] to (0)
 end
end
Now some of the stuff showed up red, but you probably know what they mean  big_smile

you forgot the question marks in some of the blocks  big_smile
I put them in for you

Last edited by joefarebrother (2012-03-16 12:59:50)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#8 2012-03-16 14:16:14

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: How to make gravity?

joefarebrother wrote:

chanmanpartyman wrote:

Here's a formula I like to use for gravity and friction:

when gf clicked
forever
 if <key [right arrow v] pressed?>
  change [xvel v] by (1)
 end
 if <key [left arrow v] pressed?>
  change [xvel v] by (-1)
 end
 set [xvel v] to ((xvel) * (.87))
 change x by (xvel)
 if <touching [level v]?>
  change x by ((0)-(xvel))
  set [xvel v] to (0)
 end
 if <key [up arrow v] pressed?>
  change y by (-1)
  if <touching [level v]?>
   set [yvel v] to (10)
  end
  change y by (1)
 end
 if <(yvel) < [3]>
  change y by (-1)
  if <not<touching [level v]?>>
   change [yvel v] by (-1)
  end
  change [yvel v] by (1)
 end
 set [yvel v] to ((yvel) * (0.9))
 change y by (yvel)
 if <touching [level v]?>
  change y by ((0) - (yvel))
  set [yvel v] to (0)
 end
end
Now some of the stuff showed up red, but you probably know what they mean  big_smile

you forgot the question marks in some of the blocks  big_smile
I put them in for you

Oh, that's what it was, I don't do this often  tongue  Thanks!

Offline

 

#9 2012-03-17 12:59:41

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: How to make gravity?

There are so many gravity topics. They should all be put in one folder.

Offline

 

#10 2012-03-18 13:28:26

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Re: How to make gravity?

This is how I do it:

when gf clicked
forever
change y by ( (0)-(gravity) )
end
If you are using scrollY, don't use the "()-()" block. Just place in the variable "gravity".

when [up arrow v] key pressed
repeat (10)
change y by (10)
end
wait until (sprite touching ground)
when gf clicked
forever
wait until <(touching ground)=(false)>
set [gravity v] to (0)
repeat until <(touching ground)=(true)>
change [gravity v] by (0.5)
end
set [gravity v] to (0)
end
Replace the "touching ground" with whatever you like: a color sensor, a variable, whatever.

Hope this helped!

Offline

 

Board footer