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

#1 2012-02-03 22:40:35

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Can't figure out!

I'm going to make a game where you have to get the bike guy to a certain color. You have to draw a hill for him to go on. I have two questions about this: First of all, how do I make the bike guy realistically go downhill, and the second question is, how do I get him to roll on a certain color????? Please help me!


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#2 2012-02-05 18:13:32

GameCentral
Scratcher
Registered: 2011-10-05
Posts: 100+

Re: Can't figure out!

the

if <touching color [#FF0000]?>
end
is uesful


http://i1237.photobucket.com/albums/ff468/sciteccf/gamecentral.gif
http://i.imgur.com/2RYxb.png

Offline

 

#3 2012-02-05 20:06:14

K-Jam
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: Can't figure out!

when gf clicked
forever
if< not touching color (color of ground)>
change y by [5]
if< touching color (color of rolling platform thing)>
turn <15> degrees
move (5) steps
something like that


http://images.inmagine.com/img/imagezoo/iz162/Iz162012.jpg COMPASS!!!

Offline

 

#4 2012-02-05 20:08:08

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

Re: Can't figure out!

Mokat wrote:

I'm going to make a game where you have to get the bike guy to a certain color. You have to draw a hill for him to go on. I have two questions about this: First of all, how do I make the bike guy realistically go downhill, and the second question is, how do I get him to roll on a certain color????? Please help me!

That's a tough one.  Technically speaking, you're looking for the parallel force (the force pulling you down an incline).  You could try storing X and Y values in a list, and use the slope that corresponds to your x-position.  The problem is, of course, if the user doubles back, creating two slopes at one x-position.

If you don't care about being that accurate, you could try to approximate the slope at a given point.  The pseudo-code would be something like:

1. find out which way the slope is going
2. Find out if the slope is 1,2, or infinite

change x by (1)
if <touching [ground color]?>     // ground is on right
change y by (1)
if <touching [ground color]?>
set [angle] to (45)
change y by (-1)
else
change y by (2)
if<touching [ground color]?>
set [angle] to (60)
change y by (-2)
else
set [angle] to (90)
end
end
else     // ground is on left
change y by (1)
if <touching [ground color]?>
set [angle] to (45)
change y by (-1)
else
change y by (2)
if<touching [ground color]?>
set [angle] to (60)
change y by (-2)
else
set [angle] to (90)
end
end
end
With more if statements, you could find the angle to a greater accuracy.

Anyway, force parallel is equal to Sine(angle)*mass*gravity

Mass*gravity will be constant, so basically:
change x by ( ([Sin](angle) )*(constant))
Edit: I just realized how un-explanatory I was being, and that that code probably looks alien to everybody except me (and trust me, in a few days, I won't be able to read it either).  Quick explanation:

Basically, the sprite shifts itself horizontally one pixel.  Then, it shifts itself vertically one pixel.  If it isn't touching the hill anymore, the angle is 45 degrees or less (I set it to 45 for simplicity).  If it is still touching the hill, the angle is steeper, so it moves up again.  Now, if it isn't touching the hill, the angle is 60 degrees or less (again, I set it to 60 for simplicity).  If it is still touching the hill, the angle is pretty steep.  So I just set it to 90.  Obviously some very approximate guesstimating.  If anyone can explain it better, please do.

Last edited by MoreGamesNow (2012-02-05 20:14:03)


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

Offline

 

Board footer