# Sonic the hedgehog physics o_<

1. May 13, 2006

### myutwo33

hi guys. I am attempting to make a sonic the hedgehog style 2d platform game, in planning all this out i'm having to go though alot of physics problems. I think I have all of them ironed out apart from the one I'm going to tell you.
when the game character runs up a curved surface (shaped like he was running up the inside of a circle), I need to be able to work out at what point of the curve will he be on, and traveling at what speed after a certain amount of time has passed. given parameters such as his previous position on the curve, his speed at that position and of course the radius of the circle the curve is made from.
I hope someone can shed some light on this, i've been trying to work it out for awhile and can;t start coding the game untill i have it nailed. I always been very intrested in physics, I was very good at working out practical problems in school (though was never great when it came to adding the actual numbers together). I decided to do animation over physics when i left school, but i figure animation is largely the study of how things move, so i still get to think about problems like this.

hope you guys can help

2. May 13, 2006

### Hurkyl

Staff Emeritus
Don't forget that physics is a secondary concern to gameplay! It's probably better just to make it do something that plays well.

That shouldn't be true at all! Not only can you start coding the other aspects of the game, but if you write well, you should just be able to code some simplistic loop handling mechanism, and replace it with a better one later. (In fact, even if you "knew" the mechanism you wanted to use, you should still code it in this way -- you might want to tweak things later!)

The simplest picture is to model your character as sliding along the loop, without any friction, or energy input. In this case you have:

(total energy) = (kinetic energy) + (gravitational potential energy) = (constant)

where

(kinetic energy) = (1/2) m v²
(gravitational potential energy) = m g h

where m is your character's mass, v is his velocity, g is the gravitational constant, and h is how high your character is.

So when you want to start using this model, you simply compute the total energy. Then, at all future times, you can simply solve the above equation for velocity. The only thing left to do is to is to figure out when your character should fall off the loop. (Or be launched into the air when he reaches a downward slope, or other similar things)

To move in a circle, the body must feel a normal force of exactly:

(normal force) = m v² / R

where R is the radius of the circle. Your character will fall when the normal component of the force of gravity is greater than this force.

3. May 13, 2006

### 0rthodontist

I think that calculation based on the normal force is what you'd want to use in most circumstances since it's more flexible in case you want other things to happen while the character is going around the loop, and it requires you to keep track of less history (it might be part of your ground-character collision detection anyway). To make the character do impossible stunts, you could rig it so that gravity decreases as the character goes towards the top of the loop.

One game I really like, Fancy Pants Adventures (http://www.fancypantsadventures.com/ [Broken]) appears (I could be wrong) to make it so that before the normal force is calculated, if the character is running, an extra force pushes him into the ground as if he were a Formula 1 race car with spoilers (though the effect disappears as soon as he stops running). This allows him to go around impossible loops and run on the ceiling in some parts of the game.

Last edited by a moderator: May 2, 2017
4. May 13, 2006

### Hurkyl

Staff Emeritus
Well, a sonic type character goes -really fast-. I don't imagine that an extra force pressing him against the ground would be necessary for loops.

(As for when the ground starts sloping downwards, that's another story)

5. May 14, 2006

### myutwo33

thats for you reply hurky. I think what you said makes sense.. but i'm a bit confused on how to go about implementing it..
I havn't really thought about using normals of force before. could you explain this a little more?

I'm going to try to explain the game problem in a little more detail so that we might understand each other a bit clearer. Firstly, i'm assuming on this curve that there is no friction, and all energy is reflected back in the player when he runs on it, as such, if there was no gravity the velocity of the character comming into the curve would be equal to the velocity of the character exiting it. I'm also pretty sure the velocity of the character will be directly porportional to it's Y position. however, the rate at which it decelerates changes as the the angle of the the chracter from the centre of the circle changes, and it is at this point that my head starts to spin :/. i need to be able to calculate the characters position in the next frame so i know where to tell the computer to draw him, and also to find out weather or not he is still in the curve. If he is not still in the curve i need to use another calculation to find out how much time passed since the last frame until he left the curve ,which could be 0.4866frames for example. i then calculate how far and where he will travel to in the game area outside of the curve in (1 - 0.4866)frames to find where to draw him in the next frame.

I know this is complicated, which may mean i need tocompletely replan how i'm going to code the game at a later point, which is why i can't start it now ~_~.