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

#1 2012-12-24 19:01:27

OrcaCat
Scratcher
Registered: 2010-06-30
Posts: 500+

Flying and Gravity physics

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)


     Awesome music     Electrode's theme     Epic music
Bye, 1.x.  sad                             Hello, 2.x!  smile

Offline

 

#2 2012-12-24 19:37:38

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Flying and Gravity physics

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2012-12-24 19:46:04

OrcaCat
Scratcher
Registered: 2010-06-30
Posts: 500+

Re: Flying and Gravity physics

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.


     Awesome music     Electrode's theme     Epic music
Bye, 1.x.  sad                             Hello, 2.x!  smile

Offline

 

#4 2012-12-25 05:11:42

dechan
Scratcher
Registered: 2012-12-20
Posts: 69

Re: Flying and Gravity physics

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

 

#5 2012-12-25 05:18:57

dechan
Scratcher
Registered: 2012-12-20
Posts: 69

Re: Flying and Gravity physics

Forgot to mention that the "Gravity Marble" script (scratch/media/costumes/things/Gravity Marble) produces a very predictable gravity effect and is easily adapted into other scripts.

Offline

 

#6 2012-12-25 05:40:39

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: Flying and Gravity physics

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


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#7 2012-12-27 10:30:20

Kileymeister_test
Scratcher
Registered: 2010-01-31
Posts: 100+

Re: Flying and Gravity physics

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)


Kileymeister's test account.  I upload engines and demos and stuff for public use.
Currently Working on: Grapple Arms!

Offline

 

#8 2012-12-27 15:14:34

3sal2
Scratcher
Registered: 2012-03-22
Posts: 100+

Re: Flying and Gravity physics

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.


http://scratch.mit.edu/static/projects/3sal2/3120946_sm.png In 2012, scientists at the LHC discovered the Higgs boson, which explains the source of the masses of the W+, W-, and Z bosons, as well as fermions.

Offline

 

#9 2012-12-31 11:14:02

minecraftpe123
Scratcher
Registered: 2012-11-18
Posts: 100

Re: Flying and Gravity physics

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

 

#10 2012-12-31 11:18:50

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: Flying and Gravity physics

Not sure, but this might help.  Not the same type of scrolling, but should do.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#11 2012-12-31 17:12:56

lalala3
Scratcher
Registered: 2008-10-03
Posts: 100+

Re: Flying and Gravity physics

1 or 2 pixels isn't a very big distance. Multiply the amount by which you change yvel by some amount.


http://img515.imageshack.us/img515/9374/signature2nt.png

Offline

 

Board footer