Trying to create a smooth burst of wind when an explosion happens, but my LERP is not working. Instead of smoothly transitioning it just instantly jumps from 0 to 1 in a single frame. I know the values are getting set properly, as I can visually see it in the editor. It just isn’t doing the LERP. (Using 2019.3b5)
Here is my code. Any idea what I’m doing wrong here?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CoverShooter;
public class ExplosionWind : MonoBehaviour
{
public float MinStart = 0f;
public float MaxVal = 1f;
public WindZone AttachedWindZone;
public DelayedDestroy AttachedDelayDestroy;
public float DestroyTime = 4f;
// Start is called before the first frame update
void Awake()
{
getWindObject();
SetStartVal();
getDelayedDestroy();
SetDestroyTime();
}
// Update is called once per frame
void Update()
{
var timer = Time.deltaTime;
if (timer <= DestroyTime) { TimerUnderHalf(); }
if (timer >= DestroyTime) { TimerOverHalf(); }
}
void getWindObject()
{
if (AttachedWindZone == null)
{
AttachedWindZone = GetComponent<WindZone>();
}
else return;
}
void getDelayedDestroy()
{
if (AttachedDelayDestroy == null)
{
AttachedDelayDestroy = GetComponent<DelayedDestroy>();
}
else return;
}
void SetStartVal()
{
AttachedWindZone.windTurbulence = 0f;
AttachedWindZone.windMain = 0f;
AttachedWindZone.windPulseMagnitude = 0f;
AttachedWindZone.windPulseFrequency = 0f;
}
void SetDestroyTime()
{
DestroyTime = AttachedDelayDestroy.Delay/2;
}
void TimerUnderHalf()
{
AttachedWindZone.windTurbulence = Mathf.Lerp(MinStart, MaxVal, DestroyTime);
AttachedWindZone.windMain = Mathf.Lerp(MinStart, MaxVal, DestroyTime);
AttachedWindZone.windPulseMagnitude = Mathf.Lerp(MinStart, MaxVal, DestroyTime);
AttachedWindZone.windPulseFrequency = Mathf.Lerp(MinStart, MaxVal, DestroyTime);
}
void TimerOverHalf()
{
AttachedWindZone.windTurbulence = Mathf.Lerp(MaxVal, MinStart, DestroyTime);
AttachedWindZone.windMain = Mathf.Lerp(MaxVal, MinStart, DestroyTime);
AttachedWindZone.windPulseMagnitude = Mathf.Lerp(MaxVal, MinStart, DestroyTime);
AttachedWindZone.windPulseFrequency = Mathf.Lerp(MaxVal, MinStart, DestroyTime);
}
}