Why my horizontal moving is much faster than vertical movement?
It is a 3D movement in a 3D space but with a 2D sprite like Ragnarok Online.
public class Player : MonoBehaviour {
[SerializeField]
private float _speed = 5f;
private CharacterController _controller;
// Use this for initialization
void Start () {
_controller = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
CalculateMovement ();
}
public void CalculateMovement()
{
float horizontalInput = Input.GetAxis ("Horizontal");
float verticalInput = Input.GetAxis ("Vertical");
Vector3 direction = new Vector3 (horizontalInput, 0, verticalInput);
Vector3 velocity = _speed * direction;
velocity = transform.transform.TransformVector (velocity);
_controller.Move (velocity * Time.deltaTime);
}
}
Answer by tormentoarmagedoom · May 25, 2018 at 10:39 PM
Can you post the object inspector? How is scaled the object ans its parents?
Good day again.
I think is caused because scale of object is 3X for each 1Z , so 3 X units equals to 1 Z units. You need to add this at your code. Try replace your direction definition for this:
Vector3 direction = new Vector3 (horizontalInput/3, 0, verticalInput);
or this:
Vector3 direction = new Vector3 (horizontalInput, 0, verticalInput*3);
So you "balance" the movement. Try it and say what you get!
Bye! :D
Answer by tallesmaziero · May 29, 2018 at 04:10 PM
It worked! Thx a lot! I'm relatively new in Unity and didn't know that the scale of the object interferes with the movement like this!
Your answer
Follow this Question
Related Questions
My controls are wierd 0 Answers
How can I state the movement speed of this script? 0 Answers
Object don't move towards. 0 Answers
Jumping in my script deosnt work,How make this script to jump? 0 Answers
Character Rotation 0 Answers
