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!
Offline
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 endWith more if statements, you could find the angle to a greater accuracy.
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:
Last edited by MoreGamesNow (2012-02-05 20:14:03)
Offline