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 v] 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 (((xvel) * (0.whatever))
 
Or, if you are not using variables, say moving changes "x" by 5.

when key [right arrow v] presses
 forever if < key [right arrow v] pressed >
  change x by (5)
 
And then....
if <touching [hard ground]
 if < key [right arrow v] 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 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 y by (([abs v] of (xvel)) + (1))
  if <touching [level v]?>
   change y by ((0) - (([abs v] of (xvel)) + (1)))
   change x by ((0)-(xvel))
   set [xvel v] to ((xvel) / (2))
  end
 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 y 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 ((yvel) / (2.5))
 end
end

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