- Home /
Question by
Yeisonlop10 · Mar 23, 2020 at 11:31 PM ·
unity 5
speed hysteresis
Hi Guys. I have a question. I'm trying to implement a C# method that creates a hysteresis behavior for a car speed and enables a boolean (positive if speed is less than 10 and negative if speed is greater than 15). Basically I'm using smoothDamp but I'm not sure about the results.
public static void isMovingSlow()
{
float velocity = 0.1f;
float smoothTime = 1.0f;
float currentSpeed = speed;
if(currentSpeed >= 10 && currentSpeed < 15)
{
float newSpeedDamped = Mathf.SmoothDamp(currentSpeed, 15f, ref velocity, smoothTime);
return !(newSpeedDamped>=15);
}
else if(currentSpeed < 15)
{
float newSpeedDamped = Mathf.SmoothDamp(currentSpeed, 10f, ref velocity, smoothTime);
return newSpeedDamped < 10;
}
return newSpeedDamped < 10;
}
The objective is to have hysteresis behavior for values between 10 and 15. What do you think? Thank you
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612225600im_/https://answers.unity.com/themes/thub/images/avi.jpg)