#Camera Interpolation

1 messages · Page 1 of 1 (latest)

sterile wedge
#

Hey all. I'm trying to implement some camera smoothing/interpolation. Here are the relevant chunks of code:

public void OnLook(InputAction.CallbackContext context)
    {
        camAngleTo = Quaternion.Euler(0, context.ReadValue<Vector2>().x/* * (mouseSensitivityX * .01f)*/, 0);
    }

void Update()
    {
        camPivot.transform.rotation = Quaternion.Lerp(camPivot.transform.rotation, camAngleTo, .01f);
    }
sterile wedge
#

:l

chrome pilot
#

I imagine you tried Google, but no good answer out of it?

jaunty ridge
#

i think free library on asset store called DOTWEEN would help you there

sterile wedge
#

Did a couple hours of looking at the documentation, and of other similar functions for vectors/quaternions

sterile wedge
jaunty ridge
#

then use IEnumerator? COROUTINE

#

public void OnLook(InputAction.CallbackContext context)
{
croutineName(camAngleTo);
}

sterile wedge
#

I would really just like a standard solution

#

I should just be able to put code in Update to do the equivalent to a coroutine

#

Right?

jaunty ridge
#

IEnumerator is part of unity but if want above example to work.

you need if basically.
Lerp works on % based, 0-1, you need to pass it start position, end position and percentage, so above example

#

over time is amount of time over which cam will move, timer as default needs to be higher than overTime

#

this should work in your example and you can optimize if statement

#

i did this below my code so throw all kinds of error

jaunty ridge
chrome pilot
#

It should be above your tab key

#

tilde

#

on the same key as tilde

sterile wedge
#

So why do I need time in this solution?

jaunty ridge
sterile wedge
#

rip eu lol

jaunty ridge
chrome pilot
jaunty ridge
#

between start and end point, and you tell it give me 0.4 position which is 40% into transformation

sterile wedge
#

Can't you just do that by passing to it a value that has changed since last lerp call?

#

So that way it'll be further along?

chrome pilot
#

just copy
```cs

```
into it

jaunty ridge
sterile wedge
#

just look up tilde everytime you need it

chrome pilot
#

Well just keep it in a fokin notepad and copy that each time lol

sterile wedge
#

or move to us

jaunty ridge
#

and something to measure how much time passed since start

jaunty ridge
sterile wedge
#

Lerp returns a value from one value to another by a maximum amount right?

jaunty ridge
#

by a maximum amount? might be that i dont understand english well enough? cant really get what youre saying

sterile wedge
#

By a maximum percentage

#

The third parameter of the function

jaunty ridge
#

never tried going over, like 150% of lerp but dont see reason why it shouldnt do that

#

thats why if is there

sterile wedge
#

I'm not saying to go over

#

If I did a lerp from 0 to 10 with .1, it would return 1, right?

#

And if I did .5 it would return 5, right?

jaunty ridge
#

yeah

#

exactly

sterile wedge
#

Ok so

#

If on every Update run, I increment the lower number, I should be able to smoothly interpolate to 10 with time

#

Even if I keep the ratio (the .1 or .5 in that example) the same

#

Unless I'm missing something in my idea

jaunty ridge
#

yeah but in that case your interpolation varies depending on fps

#

for example if at start you have 60 and at end 20 fps

#

your interpolation slows down at end but will look smoother i think

sterile wedge
#

Could I just multiply it by Time.deltaTime?

jaunty ridge
#

well yeah

sterile wedge
#

Or whatever that thing is that people do

jaunty ridge
#

just seems as my method with extra steps

#

but yeah you can

sterile wedge
#

Your method has 2 additional variables?

#

Mine wouldn't need them

jaunty ridge
#

your would still need 1 variable since you dont know last point

sterile wedge
#

I do know the last point cuz the player moved their mouse to a certain end angle

jaunty ridge
#

and would still need to hard code second one in if statement

sterile wedge
#

Right?

jaunty ridge
#

so you want to get player camera and see where along the lerp line it is to get % of how much it moved?

#

i think this would be much easier if you just tried what you want to do.
you know what method works, mine
now just modify it how you think it should work

#

change something and run it

sterile wedge
#

That's how my code is :(

#

My code is how I thought it would work

#

It even works as you see, it just returns back to the starting spot which I don't understand

jaunty ridge
#

update if changes rotation every update like yours, without if can cause lots of jittering, also your just moves it to 10% of the way right away and keeps it there