- Home /
unity player keeps rotate when using joystick as inbut
Hi everyone following is my sample script for player Movement and rotation it works smoothly till I add joystick as input then the player keeps rotating in it place
using UnityEngine;
public class PlayerMovement : MonoBehaviour { public Rigidbody RB;
// My Varibles
public float MovementSpeed = 10f;
public float RoiationSpeed = 20f;
private void Start()
{
RB.GetComponent<Rigidbody>();
}
//Update is called once per frame
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal") * Time.deltaTime * MovementSpeed;
float vertical = Input.GetAxis("Vertical") * Time.deltaTime * MovementSpeed;
float horizontalR = Input.GetAxis("InRotx") * RoiationSpeed * Time.deltaTime;
transform.Rotate(0, horizontalR, 0);
transform.Translate(horizontal, 0, vertical);
if (Input.GetButtonDown("Jump"))
{
RB.AddForce(new Vector3(0, 11, 0), ForceMode.Impulse);
}
if (Input.GetButtonUp("Jump"))
{
RB.AddForce(new Vector3(0, -11, 0), ForceMode.Impulse);
}
if (Input.GetButtonDown("Sprint"))
{
MovementSpeed = 20f;
}
if (Input.GetButtonUp("Sprint"))
{
MovementSpeed = 10f;
}
}
this is my input for player
ask.jpg
(55.5 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612224433im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player Going through colliders 1 Answer
Orbit player around center point 1 Answer
Implement moveSpeed to this object script? 1 Answer