Sign in to follow this  
witchcraft

Platformer Controls

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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this