Scratch is a tough website to make games like that. I'm beginning to think maybe this isn't possible.
Offline
Take a look around for scratch games that have a ball that does what you want. The "gravity" tag may help.
I made a rather fancy ball for the pinball game my son and I wrote, which has gravity in addition to being able to bounce off various objects:
http://scratch.mit.edu/projects/kevin_and_abe/54377
Offline
Icarlyrocks wrote:
Scratch is a tough website to make games like that. I'm beginning to think maybe this isn't possible.
Yes, it is perfectly possible to make a game like that in Scratch, and some ideas how to do the "bouncing off a hand drawn line" part have been discussed in this thread. It is a fine challange for creative thinking (and I'm pretty sure we'll see some intelligent implementations soon enough), so thank you for bringing this subject up for discussion! Maybe you could give it shot yourself.
I tend to agree with Paddle2See (sounds like a limerick...) that "some sort of approximation" will probably be the key for a smooth and successful solution.
Offline
It's would be easy to do with circular objects, so perhaps a simplified version of the game coul dbe made where you can only draw dots (which are made of sprites) rather than lines.
Offline
I've uploaded the slow (and glitchy) "slope detector" version I experimented with:
http://scratch.mit.edu/projects/Jens/98418
It's just about slope detection, no gravity and no user drawn obstacles (yet).
Unfortunately I also ran into some inconsistent online-behaviour: http://scratch.mit.edu/forums/viewtopic.php?pid=20719#p20719
Offline
Using Kevin_Karplus's project, I got it started. Now I need the ball to touch the ground and bounce off. I don't know How to do that.(I'm not very good at scratch.
Offline
Jens wrote:
... It is a fine challange for creative thinking (and I'm pretty sure we'll see some intelligent implementations soon enough), so thank you for bringing this subject up for discussion! Maybe you could give it shot yourself.
I tend to agree with Paddle2See (sounds like a limerick...) that "some sort of approximation" will probably be the key for a smooth and successful solution.
I think it's actually pretty doable, depending on how accurate you need to be. These little challenges make it tough to get anything done on my "real" project, so I'm hoping Chalkmarrow or Mayhem will post a solution soon...
Icarlyrocks wrote:
I got it started. Now I need the ball to touch the ground and bounce off.
Kevin's project should be a good guide for you, as it does bouncing from surfaces at angles. There are lots of (simple) examples in the Gravity to Games gallery: http://scratch.mit.edu/galleries/view/9206 if you are interested in seeing some different ways to handle gravity, bouncing, jumping, etc.
-MrEd
Last edited by EdnaC (2008-02-13 11:52:57)
Offline
I've got the Main Menu ready, But not the gameplay bacause the ball goes through the ground. I saved my project.
Last edited by Icarlyrocks (2008-02-13 13:13:14)
Offline
EdnaC wrote:
...I'm hoping Chalkmarrow or Mayhem will post a solution soon...
-MrEd
Heh, not till I get the last bugs out of my Ninja sidescroller
Offline
Acually, I'm getting better at scratch, but I still need someone's help with the gravity ball and surface. I do have a new best game on scratch, but It doesn't have gravity. this is it: http://scratch.mit.edu/projects/Icarlyrocks/100615
Last edited by Icarlyrocks (2008-02-16 08:05:17)
Offline
I never did look at the the link you posted for what a "gravity ball" is, but put some work into bouncing off a "random" surface. Many thanks to Jens for his slope detector, I used his technique to find the "normal" to the surface.
This is preliminary and the code is messy and uncommented, but it works OK if downloaded:
http://scratch.mit.edu/projects/EdnaC/102490
It "hangs" online, but I think I may be able to fix that. The code can be streamlined to speed it up (I think). I'm hoping to use the tangent vector to apply spin to the ball, and have the spin effect the bounce.
-MrEd
Offline
EdnaC, you might want to look up the ball in "school Pinball"
http://scratch.mit.edu/projects/kevin_and_abe/54377
or "mouse round-paddle pong"
http://scratch.mit.edu/projects/kevin_karplus/102125
The ball there bounces off of surfaces pretty well, and there is already code for bouncing off of lines and circles.
Offline
The challenge Jens and I addressed is bouncing/reflection off of a "random" surface (like something drawn on the background). The key here is detecting the slope of the unknown surface, once that is determined, the bouncing part isn't an issue. Chalkmarrow has a very nice demo of the "reflection vector" and an explaination of the vector algebra behind the method.
I got ambitious and started fiddling with having the ball also use the tangent direction of the surface (and the associated x and y unit vectors) to apply a spin when it hits, and to alter the direction based on the spin it had before the impact. This is a "fudge", as this effect would involve inertia and friction but it looks pretty neat (I've just been fiddling with fudge factors to get it looking OK).
I'm not sure what is locking up the on-line version; I added code to hide the ball and un-ghost the sprite if spacebar is pressed, but the Java version on the site hasn't been updated as of yet, so I don't know if that is part of the issue.
-MrEd
Last edited by EdnaC (2008-02-20 12:10:59)
Offline
Sorry, I had misunderstood the goal.
Determining the slope of a drawn surface is an interesting challenge.
I had considered adding a spin variable to the pinball ball, but I had not worked out yet what I wanted it to do
1) on bounces
2) on movement when not bouncing.
(Since a pinball is rolling on a surface, spin should affect its movement somewhat.)
For bounces, I was thinking adding a velocity component parallel to the surface proportional to spin, but I haven't figured out how I would want spin to change on a bounce.
For movement on a surface, there should probably be a small acceleration at right angles to the direction of movement, proportional to spin. I've not tried playing with this yet, but it would be important for a bowling simulation.
Offline
EdnaC's project is a great example! But it lags online. I should test that one out.
Offline
kevin_karplus wrote:
For bounces, I was thinking adding a velocity component parallel to the surface proportional to spin, but I haven't figured out how I would want spin to change on a bounce.
For "BouncingBall", I found the angle of the normal using an adaptation of the (rotating sprite) method that Jens used. After rotating (and color sensing) to "find" the surface, the sensor sprite turns 90 degrees and records the Tangent direction, then another 90 to record the Normal direction.
The bounce part of "Bouncing Ball" is "real", in that it uses vector algebra to find the reflection vector. I also (fudged) spin by:
Recording the "OldSpin"
Setting the new spin (after the bounce) by multiplying "VdotNormal" (how hard the ball hit the surface) by the X component of Velocity * X component of the Tangent vector + Vy * Tangent_Y.
Using the OldSpin to alter Vx and Vy of the reflected Ball Velocity Vector. (Same as setting the new spin, but with a lesser fudge factor).
Both the "Spin" and the effect of the "OldSpin" needed fudge factors. Also, Vx, Vy and Spin get some damping applied after each bounce. Without fudging and damping, the "Flubber Effect" was making the ball velocity/spin go ballistic.
For some reason, the latest changes made the project start to work OK on-line, whereas it "locked up" previously. I still see some "odd" bounces in the Java version that don't show up in Scratch. I wonder if trig functions aren't mapping correctly from Scratch to Java?
-MrEd
Last edited by EdnaC (2008-02-20 23:23:08)
Offline
how to make a game like super mario where u can jump and when u arrive to the border of the stage u go to an other stage.....
Offline
this is how to move right
<when green flag clicked>
<forever if><key[ right ]pressed?>
<change x by( 3 )
i thought i should put some scripting here so i did something simple
Offline
yes spnce is right dont do this
<when[right]key pressed>
<change x by(3
Its not smooth if you do "when blah pressed" you have to do "forever if"
Offline
Question:
I am embedding a scratch project into a rails web app. I want my website to reward the user when they finish playing the game.
My first thought was getting scratch to use hyperlinks, but I totally understand and agree that wouldn't be kid-safe.
Is there any other way I can get my website (with javascript or something) to monitor and what is going on in the scratch game and respond?
Or, Jens, would it be possible for you to include hyperlinking in chirp?
Last edited by the_hack (2008-03-03 12:41:30)
Offline
archmage wrote:
Ok people I will tell you how to implement gravity!
The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.
// First create a local variable on your sprite called yVelocity
Then put this script into your sprite.
<when green flag clicked>
<set{ yVelocity}to(0
<forever>
<change{ yVelocity }by(-1
<change y by( yVelocity
//Now that wasn't so hard was it?
Now to jump we invert gravity.
<when[ up ]key pressed>
<set{ yVelocity}to( 10
Controlling x and y velocity is an important of game design and it's good to learn about it![]()
i try that but my sprite just flies upwards and doesn't come down... if i press up he just go's faster...
Offline
funkymonkey wrote:
archmage wrote:
Ok people I will tell you how to implement gravity!
The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.
// First create a local variable on your sprite called yVelocity
Then put this script into your sprite.
<when green flag clicked>
<set{ yVelocity}to(0
<forever>
<change{ yVelocity }by(-1
<change y by( yVelocity
//Now that wasn't so hard was it?
Now to jump we invert gravity.
<when[ up ]key pressed>
<set{ yVelocity}to( 10
Controlling x and y velocity is an important of game design and it's good to learn about it![]()
but how do you make it bounce?
Negate velocity y.
So if it equals -10, change it to 10.
If you want it to bounce less high, then change it to ((-1)-(yVel)), so that from -10 it turns to 9.
Offline
archmage wrote:
Ok people I will tell you how to implement gravity!
The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.
// First create a local variable on your sprite called yVelocity
Then put this script into your sprite.
<when green flag clicked>
<set{ yVelocity}to(0
<forever>
<change{ yVelocity }by(-1
<change y by( yVelocity
//Now that wasn't so hard was it?
Now to jump we invert gravity.
<when[ up ]key pressed>
<set{ yVelocity}to( 10
Controlling x and y velocity is an important of game design and it's good to learn about it![]()
ok, i got it but my sprite just falls down to the bottom of the screen. i want a floor. also i set my walking script like this
<when[ right arrow ]key pressed>
<point in direction( 90 )
<switch to costume[ right leg ]
<move( 10 )steps>
<wait( 0.2 )secsc>
<switch to costume[ left leg ]
<move( 10 )steps>
<wait( 0.2 )secsc>
<switch to costume[ standing ]
so when i jump, if i try to go right or left then the sprite moves his legs in mid-air. can you help me? (:
Offline