- Home /
Question by
Eco-Editor · Dec 12, 2019 at 04:39 PM ·
cameramovementtransformvelocityacceleration
How do I create a rubber band effect on a camera forward movement?
Hello everybody,
In my VR scene the camera is a player and moves forward on button press, using transform.Translate().
However once the button is not pressed the camera immediately stops .
I'd like the camera to stop very smoothly, with slight rubber band effect, meaning going slightly forward and then back.
This is my script for moving forward:
var direction = mainCamera.gameObject.transform.forward * maxSpeed * Time.deltaTime * (accelerationSqrMagnitude/10);
camHolder.Translate(direction, Space.World);
Thank you
Comment
Answer by Cornelis-de-Jager · Dec 12, 2019 at 10:17 PM
Not sure how to do the rubberband effect, but smooth stopping is easy
Repalce
camHolder.Translate(direction, Space.World);
with
float delay = 2; // 2 seconds
float speed = 4;
camHolder.postion = Vector3.Lerp(camHolder.postion, camHolder.postion + direction * speed * Time.DeltaTime, delay);