# Platformer Controls

This topic is 5232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I was just wondering if anyone can help me with the math behind platformer controls. I know how to program gamepads, but I seem to be having alot of trouble getting the usual character behaviour of a typical console game. I'm just trying to make it so when I push on a direction with the gamepad, the character will face that direction and then continue to walk/run in that direction while it's pressed. Can anybody shed some light on this for me? Thanks for any help.

##### Share on other sites
what you need to do is create a Mario64 style (tether) camera and have it follow your dude around.
Now on to the walking part. To get the direction the player should walk, you need to obtain the look vector and right vector of the camera. Then you can find out what way to orient your dude like this:

Vector2 dudeOrient;
Vector3 CameraLook = Already filled in by you;
Vector3 CameraRight = Already filled in by you;
Vector2 Input = you fill this in from the gamepad;

then you go like this :
Normalize(&Input);
Normalize(&CameraLook);
Normalize(&CameraRight);
dudeOrient.X = VectorLook * Input.X;
dudeOrient.Y = VectorRight * Input.Y;

now dudeOrient represents what way your guy should be looking/walking in world space. This means that if you push left, the guy will look/walk left relative to the camera.

The tether cam is pretty simple. You just make the camera always be a fixed distance from the target. If the camera becomes further that the distance you set, you move the camera straight towards your character. That is the basics of a classic Mario64 style controlling.

Excuse my syntax, I've been programming C# for too long.

##### Share on other sites
Nice!

Hey, thanks alot, man!

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013547
×