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:
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. Heresetxvel ▼toxvel*.95
Offline
Or, if you are not using variables, say moving changes "x" by 5.iftouchinghard groundchange varaiblexvelby
And then....when keyright arrow ▼pressesforever ifkeyright arrow ▼pressedchange x by5
ififkeyright arrow ▼pressedchange x by3or whatever amount you want
Offline
I've learned it's to everyone's advantage to compile everything you can in one script:
whenclicked
foreverifkeyright arrow ▼pressed?changexvel ▼by1ifkeyleft arrow ▼pressed?changexvel ▼by-1setxvel ▼toxvel*.87change x byxveliftouchinglevel ▼?change y by+abs ▼ofxvel1iftouchinglevel ▼?change y by0-+abs ▼ofxvel1change x by0-xvelsetxvel ▼toxvel/2ifkeyup arrow ▼pressed?change y by-1iftouchinglevel ▼?setyvel ▼to10change y by1ifyvel<3change y by-1ifnottouchinglevel ▼?changeyvel ▼by-1change y by1setyvel ▼toyvel*0.9change y byyveliftouchinglevel ▼?change y by0-yvelsetyvel ▼toyvel/2.5
Offline
This should help you. See, the wiki is VERY helpful.
http://wiki.scratch.mit.edu/wiki/Simulating_Gravity
Offline