I am trying to switch between day sounds and night sounds with a little fade in-between. Currently my crossfade fades in and immediately stops playing, or sometimes it fades in when it should be fading out and I cannot figure out why for the life of me.
I think the issue is the values I’m using, I am using some strange rotation values of the sun, the values are -90 at noon, 90 at midnight, 0 at sunrise AND sunset. I think having multiple 0 values might be causing my problem?
This means I want the night sounds to fade in from -15 to 15, then the sun rotation goes up to 90, and then back down when it should fade out from 15 to -15
Is this scale causing my problems? IF I can get the sound to fade in then it stops abruptly once it hits 15.
I could put up a picture of my time cycle and when the fades should be if this was a little too confusing.
I did make some progress by making the time in the day night cycle 0-24 so now there are no repeating numbers. The problem is that the jump from 24 to 0 (which is the same time) completely breaks the crossfade.
It sounds like the problem you’re having is entirely one of “math” and not one of “sounds.” You just happen to be hearing the “sounds” as the symptom.
Let me see if I understand your requirements:
You have one set of “day sounds”
You have another set of “night sounds”
You have a time that goes from 0 to 24 at which point it jumps back to 0
You want a cross-fade value that’s 1.0 at day, and 0.0 at night, and fades smoothly between the two in the morning/evening
You should be able to do this with a couple of if statements and lerps.
Specifically, something like this might work (assuming the cross-fade time is 5=>7 for the night=>day, and 17=>19 for the day=>night fades.)
float CrossFadeValue(float time) {
if (time < 5.0 || time > 19.0) {
return 0.0; // night
}
if (time < 7.0) {
return (time - 5.0) / (7.0 - 5.0); // fade to day
}
if (time > 17.0) {
return 1.0 - (time - 17.0) / (19.0 - 17.0); // fade to night
}
return 1.0; // daytime
}
If you’re using blueprints, the logic should hopefully be simple enough to translate.
Ooo that’s good. I wasn’t thinking about it in terms of 1 = day and 0 = night.
That’s why I like these forums, its way too often that I’m totally stuck and I just need someone else more gooder at thinking than me to break it down for me.
Thanks friend, I shall name my first born Jwatte in honor of you. Assuming my baby mama allows me.