# Unity 5.2 default 3rd person controller makes character fly upwards when moving forward

I'm new to Unity, and already dealing with a problem using the default third person controller script. I am trying to move and animate the player, but I have a problem, as when I try to move the character it moves beautifully but not only vertically and horizontally - it also moves up on the y axis! It just keeps going higher and higher, and though it's quite funny, it really messes the gameplay.

Here are screenshots of what happens, and yes, I do have gravity turned on:

• Welcome to the Community! Can you please add some details in your question. Like your code snippet, screenshots etc? Jan 7, 2016 at 14:53
• Thanks :) I added the link to code it's a standard Unity script so I don't know why it wouldn't work.. I'll screenshot what happens to the character as well.. Jan 7, 2016 at 15:05
• I think you mean the Y axis. X and Z are horizontal ("ground"). Interesting problem, though. Jan 7, 2016 at 15:14
• Please add the code snippet not a link to the file. And only the interesting part :) Jan 7, 2016 at 15:20
• I am not sure what part could be responsible for this problem so I added whole code and part of it wasn't recgonised so it wasn't really useful that's why I added the link :) and yeah I meant Y but don't have good typing skills apparently.. Jan 7, 2016 at 15:32

## 1 Answer

Since they original code is not posted on this site, I am not going to click on the link. Instead, I will give you a very simple 3rd person controller script that illustrates how movement can be handled on a basic level. And to be honest, animations are much better handled using the Animation Controller Component. It uses a state machine to control the animations and you can add int parameters. In addition to the simple movement in 3rd person view, I will also comment on how you could take advantage of the Animation Controller in scripting.

using UnityEngine;
using System.Collections;

public class ThirdPersonCamera : MonoBehaviour
{
public Camera cam;
public GameObject character;
public Animator anim; // Gets the Animator component and
// is better used when it is attached to the character

void followCharacter()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
cam.transform.position -= new Vector3(1, 0, 0);
//anim.SetInt(1); if the parameter is an integer
// it will move to that specific animation
}

else if (Input.GetKey(KeyCode.RightArrow))
{
cam.transform.position += new Vector3(1, 0, 0);
}

else if (Input.GetKey(KeyCode.UpArrow))
{
cam.transform.position += new Vector3(0, 0, 1);
}

else if (Input.GetKey(KeyCode.DownArrow))
{
cam.transform.position -= new Vector3(0, 0, 1);
}
}

void Update()
{
followCharacter();
}
}

• Nice it is much appreciated! :) I'll do my best to implement this so I guess wish me luck and thanks a lot :) Jan 11, 2016 at 11:23
• Note that while the original default controller uses rigidbody to move with physics, this is a more direct approach, that will not incorporate physics as such. You would also want to at least multiply the movement by Time.deltaTime (eg. new Vector3(0, 0, (1*Time.deltaTime))), as without it, movement may be jittery, and be (frame dependant?). That is, users with more processing power will have the Update() function run more frequently than other users, and in turn will move faster. Aug 26, 2016 at 0:18