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

#1 2012-08-21 01:52:12

skykoi
Scratcher
Registered: 2012-06-30
Posts: 22

Help with coins and gravity?

I'm making this project..but it isn't finished...

I want to make it so that the coins come out of the monster in a realistic "bouncy" way. Kinda like so the coin is affected by gravity. Is it possible to do this?

Offline

 

#2 2012-08-21 08:10:49

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

Re: Help with coins and gravity?

I can not exactly type out a script for you at this moment as i am busy, but I suggest, if what you are after is a bouncing script, check out the script of the project in my signature, it might be helpful.


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

Offline

 

#3 2012-08-21 08:22:42

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: Help with coins and gravity?

For each coin sprite, make a script like this:

when clicked
hide
when i receive
monster_dead
show
go to
monster
set
yvel
to
pick random
3
to
10
set
xvel
to
pick random
-10
to
10
repeat until
touching
player
?
change y by
yvel
change x by
xvel
if
touching
ground
?
set
yvel
to
yvel
*
-1
set
xvel
to
xvel
*
0.8
else
change
yvel
by
-0.1
hide

Just remember to make xvel and yvel "for this sprite only".  smile


http://i50.tinypic.com/312u714.jpg

Offline

 

#4 2012-08-21 08:53:44

lilyo11
Scratcher
Registered: 2011-06-14
Posts: 100+

Re: Help with coins and gravity?

BirdByte wrote:

For each coin sprite, make a script like this:

when clicked
hide
when i receive
monster_dead
show
go to
monster
set
yvel
to
pick random
3
to
10
set
xvel
to
pick random
-10
to
10
repeat until
touching
player
?
change y by
yvel
change x by
xvel
if
touching
ground
?
set
yvel
to
yvel
*
-1
set
xvel
to
xvel
*
0.8
else
change
yvel
by
-0.1
hide

Just remember to make xvel and yvel "for this sprite only".  smile

after he dies do you know how to make a store so you could buy more things?

Offline

 

#5 2012-08-21 10:01:29

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: Help with coins and gravity?

lilyo11 wrote:

BirdByte wrote:

For each coin sprite, make a script like this:

when clicked
hide
when i receive
monster_dead
show
go to
monster
set
yvel
to
pick random
3
to
10
set
xvel
to
pick random
-10
to
10
repeat until
touching
player
?
change y by
yvel
change x by
xvel
if
touching
ground
?
set
yvel
to
yvel
*
-1
set
xvel
to
xvel
*
0.8
else
change
yvel
by
-0.1
hide

Just remember to make xvel and yvel "for this sprite only".  smile

after he dies do you know how to make a store so you could buy more things?

That's kinda unrelated to the topic; make a new one about it.  smile


http://i50.tinypic.com/312u714.jpg

Offline

 

#6 2012-08-21 11:14:24

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help with coins and gravity?

As an addition to BirdByte's script, you might want to add vertical friction (e.g. set [y-vel v] to ((0.95)*(y-vel))) and/or bouncing off of walls (if it isn't just a flat field).


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-08-21 12:29:22

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: Help with coins and gravity?

MoreGamesNow wrote:

As an addition to BirdByte's script, you might want to add vertical friction (e.g. set [y-vel v] to ((0.95)*(y-vel)) and/or bouncing off of walls (if it isn't just a flat field).

Yeah, do that. XP But remember to make sure that the coin doesn't get stuck in the ground by adding "change y by 1" to the "set yvel to yvel*-1" script.  smile


http://i50.tinypic.com/312u714.jpg

Offline

 

#8 2012-08-21 17:26:08

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help with coins and gravity?

Here's the easiest change I could think of.  It may even look better since it resolves the bounce in single frame:

when clicked
hide
when i receive
monster_dead
show
go to
monster
set
yvel
to
pick random
3
to
10
set
xvel
to
pick random
-10
to
10
repeat until
touching
player
?
change y by
yvel
change x by
xvel
if
touching
ground
?
change y by
-1
*
yvel
set
yvel
to
yvel
*
-0.8
set
xvel
to
xvel
*
0.8
else
change
yvel
by
-0.1
hide


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#9 2012-08-21 17:31:28

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Help with coins and gravity?

Oops, forgot walls.  I'll leave the other script up in case you don't need them:

when clicked
hide
when i receive
monster_dead
show
go to
monster
set
yvel
to
pick random
3
to
10
set
xvel
to
pick random
-10
to
10
repeat until
touching
player
?
change
yvel
by
-0.1
change y by
yvel
if
touching
wall/ground
?
change y by
-1
*
yvel
set
yvel
to
-0.8
*
yvel
set
xvel
to
0.8
*
xvel
change x by
xvel
if
touching
wall/ground
?
change x by
-1
*
xvel
set
xvel
to
-0.8
*
xvel
hide

Instead of "set [xvel v] to (pick random (-10) to (10))", you can add the monster's x velocity to a random number (like below) if you want (assuming the monster is moving at a velocity).

set
xvel
to
monster_x_velocity
+
pick random
-4
to
4


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-08-21 19:13:54

skykoi
Scratcher
Registered: 2012-06-30
Posts: 22

Re: Help with coins and gravity?

cool thanks for all the help people!!!  big_smile

Offline

 

Board footer