Here is part of what im using for my camera script right now.
if (Physics.Raycast(transform.position, direction, out hit, 1000, 9)) {
if (hit.collider.tag == "Ground") {
transform.position = new Vector3(transform.position.x, lastHeight + (distance - (hit.distance - 1)), transform.position.z);
lastHeight = lastHeight + (distance - (hit.distance - 1));
}
}
I would like to incorporate Mathf.Lerp into that but cannot get it working in the c# script. Does anyone have a example? I can get it working in java script script just fine. The main issue is I cant just use transform.position.y = …
Ive tried things like(figured it wouldn’t work but needed to try before I asked).
transform.position = new Vector3(transform.position.x, Mathf.Lerp(startHeight,endHeight,Time.time), transform.position.z);
Unless I’m overlooking something, the code in your second example should compile. What does ‘can’t get it working’ mean? If you’re getting errors, can you post them?
(Note that you probably won’t want to use Time.time as your interpolation factor. Time.time will most likely be some arbitrary value > 1, and the interpolation parameter is clamped to [0, 1], so as is you’re most likely just going to get the ‘end height’ value back every time.)
It compiles just fine but does the same thing as if it was the same as the first piece of code I posted. As far as using Time.time I was using that as a example because thats what is used in the documentation. I tried multiplying it buy 100 and still same thing as first piece of code. It just gives back endHeight.
And maybe I am not understanding Lerp correctly. I was looking for a way to move the camera up in a smooth way not such a jerk and Lerp seemed to be the trick looking at the example in the documentation. If this is the case can Lerp be used in this way when creating a vector3?
Also another piece of confusion far as using Time.time as well i’ve see others mention they use Time.time*(some value here like 60) if it works in their case(maybe it done ) then should work here.
Perfect just the explanation I was needing I think. Thank you for your help I will try what they are doing tomorrow and probably get back on here and post my code just incase it can be used by anyone else.
I think that may be an oversight in the documentation, or at best a poor example. At any rate, it certainly seems to have confused a lot of people. (As I mentioned in my earlier post, and as Eric mentioned in the other thread, in most cases using Time.time as the interpolation parameter is not going to produce the desired effect.)