Question by
billytipewhite · Apr 20, 2020 at 08:50 AM ·
rotationrigidbodyjoystick
Rotate rigid body with mobile joystick
Hi there, I am hoping someone can help me here.
I 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 X,Y axis not the Z.
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
Your answer
Follow this Question
Related Questions
Use Mobile Joystick with Unity 3d RigidBody 1 Answer
i'm using a code to make my cube walk with character controller but when i play the cube spins. 0 Answers
Rotate GameObject based on RigidBody Velocity 1 Answer
Rotations on "picked up" object 0 Answers
How to rotate my gameObject using Joystick control? 1 Answer