P
P
p4p2019-03-16 16:01:14
C++ / C#
p4p, 2019-03-16 16:01:14

Smooth wheel turning with mobile control or axis simulation Input.GetAxis("Horizontal"). How is it better?

Steering wheel control by pressing the "left" & "right" buttons. When pressed, I set bool left/right to true and when decompressed, to false , respectively. I need that when the turn button is pressed, the wheel turns smoothly and when unclenched, respectively, smoothly rises to position 0.
How I implemented it now

if (left && horizontal > -1)
                horizontal -= 0.1f;
            else if (!left && horizontal < -0.1f)
                horizontal += 0.1f;

            if (right && horizontal < 1)
                horizontal += 0.1f;
            else if (!right && horizontal > 0.1f)
                horizontal -= 0.1f;

The problem is that the wheel does not go to 0 when it is unclenched. There is always some degree of "underturn". Where did I go wrong? And is there another way without bikes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ichimitsu, 2019-03-17
@Ichimitsu

For smooth turns, use the Vector3.Lerp/Slerp or Quaternion.Lerp/Slerp functions.
It's done like this
SmoothLookAt is a parameter that tells how quickly rotation will go to lookRotation, the same for movement and Vector, this is done in Update or LateUpdate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question