- Home /
How to achieve smooth movement using the scroll wheel?
Hey, I'm working on a script and for the life of me can't figure out how to solve this.
Basically, what is supposed to happen is that whenever the player scrolls using the mouse wheel, the player moves forwards or backward. The part I can't figure out though, is how to do this smoothly.
I've got the basic movement down for the player, but even if I use Lerp functions, the movement is still jittery. Can anyone help with this? At the moment, I'm just moving the character using transform.position += ...
Many thanks!
@$$anonymous$$jipGamer Can you please show us your current (relevant) code? Generally speaking, consider setting a Vector3? target
upon scroll (an offset of the current position in the direction of the mouse wheel), then Vector3.Lerp
-move towards that target (if target != null) in the Update()
. Note if you have a CharacterController or RigidBody, even other movement approaches may be best.
This is how I'm currently moving the player: newPosition = player.transform.position += player.transform.forward * speed * scroll; player.transform.position = Vector3.Lerp(player.transform.position, newPosition, 0.1f * Time.deltaTime);
Answer by KjipGamer · Mar 12, 2020 at 08:42 AM
I figured it out, for anyone who might stumble upon this question.
I used a workaround, namely to have a separate object that I apply the jittery movement to, then use Vector3.Lerp(transform.position, secondobject.transform.position, 0.1f)
to smoothly move between the two positions
I hope this helps someone!
Cheers,
Kjip
Your answer
Follow this Question
Related Questions
Moving an object smoothly with a set distance and time 1 Answer
Problems with Lerp. 1 Answer
Move A Camera Between Two Points Smoothly 1 Answer
Smooth Camera/Object Movement 1 Answer
How to smooth my camera (Vector3.Lerp) 0 Answers