- Home /
Question by
purplebasemail · Jan 25, 2019 at 03:03 PM ·
inverted
My 3D char controls are inverted
I really like this code for a character controller it was originally meant for a 2D char controll thats why it may look weird. The issue of getting it from 2D to 3D was solved but now the controls are inverted.
Anyone know how to fix this? Thanks in advance
public class MovePlayer : MonoBehaviour {
public float moveSpeed;
private Rigidbody rb;
private Animator anim;
private bool playerMoving;
private Vector2 lastMove;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
void Start()
{
rb = GetComponent<Rigidbody>();
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
void Update()
{
playerMovement();
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
void playerMovement()
{
playerMoving = false;
if (Input.GetAxisRaw("Horizontal") > -0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
{
transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
playerMoving = true;
lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
}
if (Input.GetAxisRaw("Vertical") > -0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
{
transform.Translate(new Vector3(0f, 0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime));
playerMoving = true;
lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}
anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
}
}
Comment
I have tried with my $$anonymous$$imal knowledge but cant get it fixed XD.
Best Answer
Answer by purplebasemail · Jan 25, 2019 at 04:59 PM
I figured it out. i put my camera on the other side of the character!
Answer by xxmariofer · Jan 25, 2019 at 03:10 PM
Change all Vertical for Horizontal and Horizontal for Vertical (if your animation is also inverted also the LastMoveX and LastMoveY)