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

#1 2012-03-29 18:41:19

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Physics Help!

Hello Scratchers of Help With Scripts,
I am trying to make a physics game... I know people have posted this a hundred times but... I need a great, long, hard script for friction and gravity... I think I already have gravity... but it needs friction...  smile


Get ready for domination of:  tongue

Offline

 

#2 2012-03-29 19:32:08

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

Re: Physics Help!

coolhogs wrote:

Hello Scratchers of Help With Scripts,
I am trying to make a physics game... I know people have posted this a hundred times but... I need a great, long, hard script for friction and gravity... I think I already have gravity... but it needs friction...  smile

Friction is usually done by taking your velocities and multiplying them by a number x where 0<x<1.  Usually, .9<x<1 is a good place to start, since anything lower than .9 slows the sprite down extremely fast.  All you do for a script is:

set
xvel
to
xvel
*
.95

I also have a script on my test account that allows you to pick a top speed and a friction to determine how much each press of a key should change your x and y. Here


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

Offline

 

#3 2012-04-11 16:18:11

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Physics Help!

if
touching
hard ground
change varaible
xvel
by

Or, if you are not using variables, say moving changes "x" by 5.

when key
right arrow
presses
forever if
key
right arrow
pressed
change x by
5

And then....
if
if
key
right arrow
pressed
change x by
3
or whatever amount you want


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#4 2012-04-11 16:39:47

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

Re: Physics Help!

I've learned it's to everyone's advantage to compile everything you can in one script:

when clicked
forever
if
key
right arrow
pressed?
change
xvel
by
1
if
key
left arrow
pressed?
change
xvel
by
-1
set
xvel
to
xvel
*
.87
change x by
xvel
if
touching
level
?
change y by
abs
of
xvel
+
1
if
touching
level
?
change y by
0
-
abs
of
xvel
+
1
change x by
0
-
xvel
set
xvel
to
xvel
/
2
if
key
up arrow
pressed?
change y by
-1
if
touching
level
?
set
yvel
to
10
change y by
1
if
yvel
<
3
change y by
-1
if
not
touching
level
?
change
yvel
by
-1
change y by
1
set
yvel
to
yvel
*
0.9
change y by
yvel
if
touching
level
?
change y by
0
-
yvel
set
yvel
to
yvel
/
2.5

Offline

 

#5 2012-04-11 16:54:26

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Physics Help!

This should help you. See, the wiki is VERY helpful.  big_smile
http://wiki.scratch.mit.edu/wiki/Simulating_Gravity

Offline

 

Board footer