Hello guys I am having trouble with rotating a character with the right and left Joysticks. I have a very basic movement script and can not get the character to rotate with the right joystick as much as I want it to.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class PlayerMovement : NetworkBehaviour
{
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!isLocalPlayer)
return;
var x = Input.GetAxis("Horizontal") * 0.1f;
var z = Input.GetAxis("Vertical") * 0.1f;
transform.Translate(x, 0, z);
// Right Stick is mapped to HorizontalR and VerticalR
}
}
I made a test project to see if i could rotate a cube with this code. With a little bit of editing, I could.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Player : NetworkBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer)
return;
var x = Input.GetAxis("Horizontal");
var z = Input.GetAxis("Vertical");
transform.Rotate(x, 0, 0);
// Right Stick is mapped to HorizontalR and VerticalR
}
}
Instead of using transform.Translate, i used transform.Rotate.
Also, you may notice that I didn’t use your “z” variable. by doing so, the cube could only rotate over 1 axis (X-axis in this case). Using the vector (x, 0, z) allowed it to rotate very strangely.
Hope this helps at least a little bit (:
small edit: thanks to you reminding me I could simply use this, I finally got my rotating working for my school project. Thanks! (: