- Home /
Question by
billytipewhite · Apr 18, 2020 at 07:35 PM ·
rotationrigidbodyjoysticks
Rotate rigid body with mobile joystick
Hi there, I am hoping someone can help me here.
I'm using a joystick pack from the asset store, the current code let's me move my rigid body along the X,Z axis. I am trying to get the joystick to rotate the 3D object on the Y axis.
Could someone help me please, the current code is below, Cheers.
public class JoyStickOne : MonoBehaviour
{
protected Joystick joyStickOne;
// Start is called before the first frame update
void Start()
{
joyStickOne = FindObjectOfType<Joystick>();
}
// Update is called once per frame
void Update()
{
var rigidbody = GetComponent<Rigidbody>();
rigidbody.velocity = new Vector3(joyStickOne.Horizontal * 5f,
rigidbody.velocity.y,
joyStickOne.Vertical * 5f);
}
}
Comment