- Home /
Controller Movement Problem
Hello,
I'm trying to get the complete movement on the left thumbstick of my xbox 360 controller. The ship rotates correctly to the angle of the thumbstick. It just doesn't move in that same direction. For some weird reason, up=up, down=up. And many other weird things like that. There is also a problem with the rotation. When releasing the thumbstick, the player snaps back at the closes 90 degree angle (90, 180, 270, 360).
The code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float movementSpeed = 5.0f;
public float rotationSpeed = 5.0f;
public float speed;
void Start()
{
}
void Update()
{
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
float angle = Mathf.Atan2(x, y) * Mathf.Rad2Deg;
//Thumbstick is being used
if (x != 0.0 || y != 0.0)
{
transform.Translate(x * Time.deltaTime * movementSpeed, 0, y * Time.deltaTime * movementSpeed);
transform.rotation = Quaternion.Euler(new Vector3(0, angle, 0));
} else //thumbstick is not being used so do not change the angle back.
{
return;
}
}
}
Did you look at the values of x and y? $$anonymous$$aybe there's something wrong in the input manager.
The inputs in the input manager are at their default values. If I disable the rotation commands the movement is correct. So I think that the rotation and movement commands or working against each other or something.
Answer by Delthrox · Oct 07, 2016 at 12:47 PM
I have fixed the movement problem. I had to use transform.position instead of transform.Translate. Still have the snapping to a 90degree angle problem though.
Your answer
Follow this Question
Related Questions
SimpleMove not working on Y axis? 1 Answer
Player acts weirdly when I release movement input 0 Answers
Fliping character 180 degrees when moving left 1 Answer
How do I keep my character facing the direction of travel after movement stops? 1 Answer
What is the best way to move a character for an FPS? 1 Answer