- Home /
Question by
aayushunity · May 30 at 02:47 PM ·
joystick
joystick does not work properly
i am using joystick in this. when i moves joystick left it faces left but while facing left when i am moving forward it comes back to original position and moves forward i want that when i turn left and then forward i want it moves forward with left direction. Please Help
Here it is my code
public float speed = 2; private Rigidbody rb; public Animator animator; public FixedJoystick joystick; public Camera cam; public float a;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
rb.velocity = new Vector3(joystick.Horizontal * speed, rb.velocity.y, joystick.Vertical * speed);
if (joystick.Horizontal >= .2f || joystick.Horizontal <= -.2f || joystick.Vertical >= .2f || joystick.Vertical <= -.2f)
{
animator.SetBool("RunUp", true);
transform.rotation = Quaternion.LookRotation(rb.velocity);
}
else
{
animator.SetBool("RunUp", false);
}
},if i am moving the player with joysitck left and then my player faces left then when i move forward it automatically turns at its original position and move forward. I want that if my player faces left and i move the joystick up then my player moves forward on left side.
Here it is my code public float speed = 2; private Rigidbody rb; public Animator animator;
public FixedJoystick joystick;
public float jump;
bool isGrounded = false;
public Camera cam;
public float a;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
rb.velocity = new Vector3(joystick.Horizontal * speed, rb.velocity.y, joystick.Vertical * speed);
if (joystick.Horizontal >= .2f || joystick.Horizontal <= -.2f || joystick.Vertical >= .2f || joystick.Vertical <= -.2f)
{
animator.SetBool("RunUp", true);
transform.rotation = Quaternion.LookRotation(rb.velocity);
}
else
{
animator.SetBool("RunUp", false);
}
}
Comment
Your answer
Follow this Question
Related Questions
Joystick Angle Problems 0 Answers
Change the position of the Joystick by tap 2 Answers
Xbox controller joystick axis small movements? 1 Answer
How to implement joystick? 0 Answers