I need to make a player movement depending of camera rotation, i can move forward from camera rotation but i have problems with the lateral movement and the character rotation to his direction.
public class PlayerController : MonoBehaviour
{
public Camera cam;
public float speedMove;
private Vector3 camForward, movement;
private float forwardMove, horizontalMove;
void Start () {
}
void Update () {
camForward = cam.transform.forward;
forwardMove = Input.GetAxis("Vertical");
horizontalMove = Input.GetAxis("Horizontal");
camForward.y = 0;
print(camForward);
if (forwardMove != 0)
{
movement = camForward * forwardMove;
}
if (horizontalMove != 0)
{
transform.Translate(Vector3.right * horizontalMove * Time.deltaTime * speedMove, Space.Self);
}
transform.Translate(movement * speedMove * Time.deltaTime);
}
}
This is the idea: