public class playerController : MonoBehaviour
{
public Joystick input;
public float moveSpeed;
public float turnSpeed;
public float tilt = 0.5f;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// Joystick left and right
float horizontalMovement = input.Horizontal;
//////// Only one of the following 1. works. //////// I want to do togather!!
// 1. Global Z axis Rotation
transform.Rotate(0, 0, horizontalMovement * turnSpeed * Time.deltaTime, Space.World);
// 2. At that time, Local Y axis Tilting
Vector3 movementVector = new Vector3(horizontalMovement, 0f, 0f);
rb.velocity = movementVector * moveSpeed;
rb.rotation = Quaternion.Euler(0.0f, rb.velocity.x * -tilt, 0.0f);
transform.localRotation = rb.rotation;
}
void FixedUpdate()
{
if (rb != null)
{
// Local Y axis default Forwarding
rb.velocity = transform.up * moveSpeed * Time.deltaTime;
}
}
}
I want to know why not work 2.
Thanks Regard