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

#1 2012-05-24 08:51:34

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Help with 2012 Scratch Day Competition game!

Hey guys, I am posting this topic here because i am in need of semi-urgent help for my scratch project. Basically, My school attended scratch day 2012, and we were set with a competition, a simple one, to make a game, but the only catch is it needs to include a type of 'force'. i have chosen gravity, and i have developed a preety good script for it (ask if you would like to see it). But, now i am stumped, i am creating a kind of missile game, the aim is to shoot the missile up into the sky at an angle, and i would like the missile to come down in a curve, just like in real life. And for the love of god i can not figure out how to do this, so any help will be appreciated!
Thanks

Dan Jones

P.S the winner of the Competition wins an IPod, so i kind of want to win!


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#2 2012-05-24 09:16:42

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Help with 2012 Scratch Day Competition game!

Wow! Such a good prize! But may I see the script? Perhaps see TM_'s "shoot it!" here.

Last edited by jontmy00 (2012-05-24 09:19:26)


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#3 2012-05-24 13:07:07

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Help with 2012 Scratch Day Competition game!

Wow, I hope you win too!

It would be helpful to me to know what math and science classes you are taking. Have you taken algebra? Trig? Physics?

I'll explain some of the physics and math necessary here. Sorry if you already know what I'm telling you.  smile

-- First you'll need a starting velocity stored in a variable. I'll call it velInit. The way you get that velocity is up to you. Maybe you could use a slider variable or the ask function. Or, you could use the mouse's distance to the cannon to determine the velocity by putting this in the cannon's scripts:
           

set [velInit v] to (distance to [mouse-pointer v])
-- You'll also need a launch angle stored in a variable. I'll call in angleInit. Once again, you'll need to choose how to get the angle. If you want to use the mouse, the easiest method might be to have the cannon point towards the mouse, and then find the angle the cannon is pointing with this cannon script:
           
point towards [mouse-pointer v]
set [angleInit v] to ([90] - (direction) )
To correct for Scratch's angle system, you'll have to put 90-direction so the upcoming trig will work.
--Then, you'll need to separate initial velocity in the x (velInitX )and initial velocity in the y (velInitX). For this, you'll need trig. I can explain the trig to you if you want, but here are the script you'll need:
set [velInitX v] to ((velInit) * ( [cos v] of (angleInit) ))
set [velInitY v] to ((velInit) * ( [sin v] of (angleInit) ))
-- Now, you'll need two more variables: the initial starting position of the missile in the x (initX) and the initial starting position in the y (initY). Set initX and initY at the beginning of the project. They are constants. 
-- You'll also need a variable for time throughout the launch. I'll call it t. Set it to 0 at the beginning of the project.
-- We'll need physics to launch it. If you need any more explanation on anything  I write, don't hesitate to ask.
-- Throughout the launch, the velocity in the x stays constant (assuming there is no air resistance or anything) because the acceleration is 0. There is, however, acceleration due to gravity in the y: -9.8m/s^2, assuming that we are on Earth. This is what causes the missile to go in an arc.
--The scale of you project is up to you. Is 1 pixel equal to a meter? 10 pixels? 20? I'll write these script assuming one pixel is one meter. but you should change it to fix your needs.
-- Once the launch begins, you'll need to increment t by 1 every second and then find the x and y positions of the missile at that time t.  You'll have to repeat this until the missile has reached whatever you establish as the "ground." I'll make the ground at y = -180.
   
repeat until < (y position) < [-180] >
   wait (1) secs
   change [t v] by (1)
   broadcast [Find X and Y v]
   end
   
Having it update once a second will probably be choppy, so you may want to change both 1's to .5's or .1's.
-- To find the new x and y positions, you'll need the kinematic equation x= x0 + v0t + 1/2 * a t^2. As I established, accel in the x is 0, so the equation for x will be:
 ((initX) + ((velInitX) * (t)))
-- Like I said, there is an acceleration in the y: -9.8. So, the new y position is:
 (((initY) + ((velInitY) * (t))) + ([-9.8] * ((t) * (t))))
-- As a result, the missile's script to find x and y at each point in time is:
when I receive [Find X and Y v]
go to x: ((initX) + ((velInitX) * (t))) y: (((initY) + ((velInitY) * (t))) + ([-9.8] * ((t) * (t))))
I wish you luck! If you need any more explanation of this, just let me know.  smile

Last edited by scmb1 (2012-05-24 13:22:03)


http://i48.tinypic.com/2z5pqad.png

Offline

 

#4 2012-05-25 04:58:29

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Help with 2012 Scratch Day Competition game!

Hey scmb1, thanks for your help, but sadly i am only in year 9 and taking simple science and math. But i do understand Algebra, but none of that Cos Sin stuff HaHa! xD. At the moment this script you provided is excellent, but it seems to be a bit over my head, i understand the actual idea behind it, but still i am yet to fully understand it. I will go over it again a few times to try understand it. It's funny, i can spit out a HTML script or even a VBScript script with ease, but i struggle with scratch's simple GUI, possibly because i am use to actually inputing the script by well, 'scratch'. haha.
Thanks heaps
Dan Jones

PS. I will be sure to add your name to my project for helping!


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#5 2012-05-25 05:01:46

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Help with 2012 Scratch Day Competition game!

Oh yeah! one more thing, my script for the gravity i put together is in my projects, i think i successfully pulled it out of my game correctly lol. I will put my game online when I (hopefully) win the competition!


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#6 2012-05-25 13:50:28

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Help with 2012 Scratch Day Competition game!

Looks great! Good luck.  smile


The trigonometry (cos and sin) is only necessary to split the velocity into x and y components because the x and y velocities change at different rates. (x velocity doesn't change at all; y velocity changes at a rate of -9.8). The trig script I gave you is all you will probably need. Once you do that, algebra should help you with the rest.

Here is a table that might help you understand the trig:

http://i47.tinypic.com/11r9hlv.jpg

In your project, velInit is the hypotenuse, velInitX is the side adjacent to the angle and velInitY is the side opposite the angle.

Here is how you can solve for velInitX:

-- Use trig to find
cos(angleInit) = velInitX/velInit
-- Now, multiply velInit to both sides.
  velInit * cos(angleInit) = velInitX

Solving for velInitY is basically the same, but with sine (sin) instead of cosine (cos)"

--  sin(angleInit) =velInitY/velInit
-- Multiply velInit to both sides.
  velInit * sin(angleInit) = velInitY

Last edited by scmb1 (2012-05-25 13:51:39)


http://i48.tinypic.com/2z5pqad.png

Offline

 

#7 2012-05-25 21:37:56

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Help with 2012 Scratch Day Competition game!

o.o, i think i understand now, lol, i never expected to be learn math on a saturday! xD
Just wondering if you could check ou my new gravity and walking script at http://scratch.mit.edu/projects/daniel_j/2565935 I am hopefully going to combine your exxcelent math lesson and this script into a game.... Thank god i have 1 school term to complete it lol!

thanks


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#8 2012-05-26 16:14:51

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Help with 2012 Scratch Day Competition game!

Looking good! I can't wait to see the next versions.  smile


http://i48.tinypic.com/2z5pqad.png

Offline

 

#9 2012-05-27 00:09:44

Yoshiboy
Scratcher
Registered: 2011-12-30
Posts: 1000+

Re: Help with 2012 Scratch Day Competition game!

I sure hope you win! That would be amazing!


Winter...

Offline

 

#10 2012-05-27 03:18:44

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: Help with 2012 Scratch Day Competition game!

Thanks Yoshiboy!


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

Board footer