Hello,
I’ve been trying to make my game work with an xbox controller, i kinda got it working, everything works execept for some axis which i need to invert.
But it’s moving by itself without any input.
i have displayed the input on the screen and as you can see if acts weird.
Once i stop giving input unity just goes back to a default input as it seems.
I really hope someone can help me out!
This is the code
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public static float mouseSensitivityX = 200f;
public static float mouseSensitivityY = 200f;
public static float walkSpeed = 8f;
public GameObject cameraT;
Rigidbody rb;
Vector3 moveAmount;
Vector3 smoothMoveVelocity;
float verticalLookRotation;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivityX);
verticalLookRotation += Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivityY;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -60, 60);
cameraT.transform.localEulerAngles = Vector3.left * verticalLookRotation;
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
Vector3 targetMoveAmount = moveDir * walkSpeed;
moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
}