Problem is not reproducible or outdated
Movement Issue
When I move my character along the X axis its Z position changes slightly and vice versa. My movement scipt is:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private float maxSpeed = 5f;
private Vector3 input;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
if (rigidbody.velocity.magnitude < maxSpeed)
{
rigidbody.AddForce (input * moveSpeed);
}
}
}
i recommend changing your input completely horizontal and vertical axis input can be locked down but you'll bet getting a performance hit. it's best to just not use them at all and custom make input for whatever keys you want to use. Unity is kinda bad when it comes to x/z 2d wish you could choose the coords for 2d rigidbody ect ect that would be extremely awesome...hopefully a future feature?
Could you please clearify what you mean, I am still very new to Unity.
I tested your code and it works just fine. There must be some another factor that is responsible for this behavior. $$anonymous$$ake sure 1. your "Edit>Project Settings>Input" aren't messed up somehow 2. no other scripts are attached to your object that can be doing that 3. look for unwanted collisions with world etc.
Answer by hamburger1000 · Apr 07 at 02:15 AM
can you please send a video on the issue I could 100% solve it if I had a visual of the problem
Answer by ttank7 · Apr 07 at 03:04 AM
When using a rigidbody to represent a character, there is some degree of control that you'll have to be willing to give up so that the physics engine can go to work. For example, unless you specifically compensate for it, a rigidbody character will slide down slopes.
However, there are strategies you can use to improve the behaviour when working with rigidbodies.
For instance, you can formulate your forces to control velocity more directly. Given a desired velocity, and the current velocity, you can create a force based on the difference between them. This way, if other forces are acting on the character that push him in the wrong direction, they'll be corrected out by your forces.