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...
Offline
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...
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
Offline
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
Offline
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
This should help you. See, the wiki is VERY helpful.
http://wiki.scratch.mit.edu/wiki/Simulating_Gravity
Offline