K
K
KraGen.Developer2021-09-06 16:09:56
Unity
KraGen.Developer, 2021-09-06 16:09:56

How to rotate the sphere with a joystick:?

There is a 3D sphere in the 2D game and there is a joystick, you need the sphere to rotate with the joystick.
The player turns the joystick and the joystick turns the sphere. Someone knows how to do this, otherwise I'm not boom boom?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farawa, 2021-09-15
@KraGenDeveloper

you take a joystick from the asset shop, it will give you x and y values ​​from -1 to 1.
then you take and rotate the ball through x and z.
sample code:

Vector2 input = joystick.input;
            Transform sphere = sphereObject;
            float rotateSpeed = 10;

            var euler = sphere.eulerAngles;
            euler.x += input.x * rotateSpeed;
            euler.z += input.y * rotateSpeed;
            sphere.eulerAngles = euler;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question