I don't understand why this doesn't work properly.
Please help!
Scripts:
when I receive [start] forever set (dir) to ((90) - (direction))//Scratch has weird angles, I'm fixing it!! when green flag clicked hide when I receive [start] set (vel) to (0) set (yvel) to (0)//set variables show forever if <key right arrow pressed?> turn cw (1) degrees end if <key left arrow pressed?> turn ccw (1) degrees end if <key down arrow pressed?> //It is opposite what you would think because //we are dealing with scrolling change (vel) by (0.1) end if <key up arrow pressed?> change (vel) by (-0.1) end change (yvel) by (((vel) * ( [sin] of (dir))) + (0.2))//0.2 is gravity. Sin of dir is // basic right triangle trig change (scrolly) by (yvel) change (scrollx) by ((vel) * ( [cos] of (dir)))//more trig set (yvel) to ((yvel) * (0.95))//air resistance set (vel) to ((vel) * (0.95))Why does it rise and fall so much but there is not much x change? Why is the gravity not accelerating? Thanks!
Last edited by OrcaCat (2012-12-25 13:25:26)
Offline
Are you sure you don't want to Set Yvel to that expression, not Change it by it? It might depend on how you are using Yvel to change the Y coordinate. But normally when I get the Y component of a vector, I use Set rather than Change.
Offline
Paddle2See wrote:
Are you sure you don't want to Set Yvel to that expression, not Change it by it? It might depend on how you are using Yvel to change the Y coordinate. But normally when I get the Y component of a vector, I use Set rather than Change.
I'm sure, when I do change, the gravity doesn't accelerate at all. But that may be the root of the problem.
Offline
Hi, I saw this great article featured on ynews a little while ago. Hope everyone remembers their Trig! When I get done with my current Scratch projects I'll work on incorporating this into something ballistic. At least the math in this article is easily incorporated into Scratch.
http://www.niksula.hut.fi/~hkankaan/Homepages/gravity.html
Offline
I can see that the gravity has stopped accelerating because it has reached terminal velocity. This is because the multiplication by 0.95 is eventually equivalent to the increase in y-velocity.
I think the reasin the Y is going so fast is because you have added in the gravity in the movement but I am not sure
Offline
Y is increasing much more because of your separate yvel variable. If I'm reading the script right, and if I it's trying to do what I think it is, then I would say that it would probably work better if you changed scrolly directly by the function that yvel is being changed by, similar to how scrollx is being changed.
Except that would recreate a situation identical to what Paddle2See suggested, and that didn't seem to work. Back to thinking.
Last edited by Kileymeister_test (2012-12-27 10:33:23)
Offline
But it sounds realistic...
As a body falls through a fluid, it speeds up because of gravity. As the object's speed increases, so does the fluid friction, because there are more molecular collisions. Eventually the object is falling so rapidly that gravity and fluid friction cancel each other out, and the object stops accelerating. The final speed of the object is called the terminal velocity.
Offline
OrcaCat wrote:
I don't understand why this doesn't work properly.
Please help!
Scripts:when I receive [start] forever set (dir) to ((90) - (direction))//Scratch has weird angles, I'm fixing it!! when green flag clicked hide when I receive [start] set (vel) to (0) set (yvel) to (0)//set variables show forever if <key right arrow pressed?> turn cw (1) degrees end if <key left arrow pressed?> turn ccw (1) degrees end if <key down arrow pressed?> //It is opposite what you would think because //we are dealing with scrolling change (vel) by (0.1) end if <key up arrow pressed?> change (vel) by (-0.1) end change (yvel) by (((vel) * ( [sin] of (dir))) + (0.2))//0.2 is gravity. Sin of dir is // basic right triangle trig change (scrolly) by (yvel) change (scrollx) by ((vel) * ( [cos] of (dir)))//more trig set (yvel) to ((yvel) * (0.95))//air resistance set (vel) to ((vel) * (0.95))Why does it rise and fall so much but there is not much x change? Why is the gravity not accelerating? Thanks!
I believe that to solve the angle problem it should be direction - 90. Hope this helped with the problem of that.
Offline
Not sure, but this might help. Not the same type of scrolling, but should do.
Offline