using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float Speed;
float h;
float v;
Rigidbody rigid;
public Vector3 newPos;
bool isWalking;
Animator anim;
int floorMask;
void Start () {
rigid = GetComponent<Rigidbody> ();
anim = GetComponent<Animator> ();
floorMask = LayerMask.GetMask("Floor");
}
void FixedUpdate () {
v = Input.GetAxisRaw("Vertical");
h = Input.GetAxisRaw("Horizontal");
Move (h,v);
Animate ();
Turn ();
}
void Move(float h, float v){
newPos = new Vector3 (h,0f,v);
newPos = newPos * Time.deltaTime * Speed;
rigid.MovePosition (transform.position + newPos);
}
void Animate(){
isWalking = h != 0f || v!= 0f;
anim.SetBool ("isWalking", isWalking);
}
void Turn(){
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if(Physics.Raycast(camRay,out floorHit,100f,floorMask)){
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0;
Quaternion newRot = Quaternion.LookRotation(playerToMouse);
rigid.MoveRotation(newRot);
}
}
}
So I have this simple movement script for my top-down project, the Move() function does all the movement, my character seems to be moving faster on the X axis than on the Z axis, I measured the ratio and it is always 1.5 or 1.6 times faster than what it should be, or Z is 1.6 times slower than what it should be.
I tried looking at the Input Settings-> Axis, but all the variables for Horizontal were the same as Vertical. I even tried multiplying the “v” variable by 1.6 in order to catch up to the horizontal speed, still didn’t work, then I tried to check if v is even changing and multiplied it by 100, but it moves the same speed. Please help