• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[MATH] Strong at Night, Weak During Day spell

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
So I want to create a spell that is stronger towards midnight (0.00) and weaker towards day. (12.00)

The problem is, the second before midnight is 23.99, so the GetFloatGameState command in JASS has to be converted into an algorithm that properly creates a zenith at midnight and a nadir at noon.

Does anyone know how to convert these numbers to do this?
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Would a function like this fit your needs?
attachment.php

The formula is ((cos(time * pi / 12) + 1) / 2) * (max - min) + min
Where
"time" is daytime between 0 and 24.
"min" and "max" are minimum and maximum values the function can yield.
 

Attachments

  • graph.png
    graph.png
    7.9 KB · Views: 188
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,378
Just a note here:
When the daytime becomes 00:00> and <12:00 then set a boolean Night to true, when it becomes 12:00> and <23:59 set Night to false.
Your logic here is wrong.
For example 11:00 AM is not exactly night. If anything, he would need to set 6 AM as start of day and 6 PM as start of night (this is the default day/night time in wc3).
 
Level 11
Joined
Jan 23, 2015
Messages
788
Just a note here:

Your logic here is wrong.
For example 11:00 AM is not exactly night. If anything, he would need to set 6 AM as start of day and 6 PM as start of night (this is the default day/night time in wc3).

Yes I know, but that can be changed, so when he said he wants the unit get stronger towards 00:00 and weaker towards 12:00, I thought his night begins at 00:00 and day at 12:00 and he wants the unit to become stronger when night begins, but I got what he was sayin' later.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
As Garfield1337 said, use the sine/cosine functions by converting the time into an angle. Due to the circular nature of angles it can be used to mask the discontinuity with time. You just need to make sure that the full day fits exactly into an integer multiple of a circle (360 degrees or 2pi is a full circle).
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
It works for boosting skills during the day, but I'm not sure how to inverse the algorithm for night. Would I use sin instead of cos?

That equation already represents for both day and night. You will only use a single equation mentioned by Garfield1337 which is a cosine. Using sine will shift the phase by 90 degrees and will not invert. Adding a pi phase offset on the cosine will invert it making the max at 12 and min at 0.
 
Status
Not open for further replies.
Top