views:

293

answers:

2

I am working on a simple 2D openGL project. It contains a main actor you can control with the keyboard arrows. I got that to work okay. What I am wanting is something that can help explain how to make another actor object follow the main actor. Maybe a tutorial on openGL. The three main things I need to learn are the actor following, collision detection, and some kind of way to create gravity. Any good books or tutorials to help get me in the right direction would be great.

+1  A: 

You could use a physics library like Chipmunk Physics, which lets you attach springs and things between the two objects and detect when they hit each other and other things.

Marcelo Cantos
+1  A: 

A pre-rolled library would be good, but the concepts you describe are ones you need to know if you are going to do any sort of game programming anyways:

A simple way to make one actor follow behind another is to have the lead actor store its position every time it moves. Feed these positions to a trailing actor with a delay of a few values - the longer the delay, the further behind they travel. Simple, but doesn't handle dynamic collision (other actors moving the block collision.)

Collision detection in 2D can simply be axis aligned (AA) bounding boxes. Search for this and you'll see the 4 ifs or so that are needed.

Gravity is just adding a fixed velocity (usually down) to every object every game loop. This is constant acceleration which is exactly how gravity works.

Michael Dorgan
How do you make an actor move to a specific point? I know how to make and object move with a keyboard command but I do not know how to make another object move to a specific point.
shinjuo
Form a vector from the current position to the new point. Normalize it. Now multiply that vector by a scalar velocity you want your actor move. It will now move at that velocity towards your point. When it overshoots the point, set it to the point and you are done.
Michael Dorgan