c# - Unity lerp doesn't lerp, it just moves immediately -
i cannot life of me figure 1 out. exact code works correctly camera.main
object. door needs lerp
when activated external switch, reason no matter value put in there jumps up, doesn't move prefer. code placed in void update()
block, ideas? doing wrong, misunderstanding use of lerp
?
private transform objtransform = null; public bool isdooropen = false; private vector3 posdoorstart; public vector3 posdoorend; public float doorsmoothing = 2.0f; // use initialization void start () { objtransform = transform; posdoorstart = transform.position; } void update() { if (isdooropen) { float smoothing = doorsmoothing; // tried this... // float smoothing = doorsmoothing * time.deltatime; transform.position = vector3.lerp(posdoorstart, posdoorend, smoothing); } }
transform starting values:
gate script values:
also, on occasion if set lerp low, in example, partially moves location want. has hit around 1.5
before it'll go way up, otherwise this...
got door working peeeeeerfectly! extremely smooth , no isdooropen
variable can private. generated public method kick off door opening. tried put time.time
setting in start
method, figured out made silly jump first movement, set @ time of activation , fixed issues. door fixed.
private transform objtransform = null; private float starttime; private float distancttotravel = 0.0f; private bool isdooropen = false; private vector3 posdoorstart; public vector3 posdoorend; public float doorsmoothing = 1.0f; void start () { objtransform = transform; posdoorstart = transform.position; } void update() { if (objtransform != null) { if (isdooropen) { float distcovered = (time.time - starttime) * doorsmoothing; float smoothing = distcovered / distancttotravel; transform.position = vector3.lerp(posdoorstart, posdoorend, smoothing); } } } public void opendoor(){ starttime = time.time; isdooropen = true; distancttotravel = vector3.distance (posdoorend, posdoorstart); }
Comments
Post a Comment