I’m planning to make a test game similar to samurai run (android), basically i have to control the direction of the player with the horizontal joystick as the player moves in continuously… And I’m a bit stuck on figuring how to make the player (rigidbody) rotate around Y-axis while moving forward… I wrote a script to the player model to move forward automatically…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mover : MonoBehaviour
{
void Update()
{
transform.position += transform.forward * Time.deltaTime * 20;
}
}
And that scripts work without issues. But not the following one which I wrote to change the rotation when I moved the joystick horizontally.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class turner : MonoBehaviour
{
public Joystick joystick;
public float rotateVertical;
public float rotateHorizontal;
void FixedUpdate()
{
rotateVertical = joystick.Vertical;
rotateHorizontal = joystick.Horizontal * 5f;
transform.Rotate(0,rotateHorizontal,0);
// rigidbody.rotation = rigidbody.rotation * Quaternion.AngleAxis( joystick.Horizontal * 5, Vector3.Foward);
}
}
Transform.rotate works if I havent made this as an rigibody as usual, I cant get it to work with rigidbody.
How should I adress this coding issue?