A tidal range on region water

Creating scripts
Post Reply
User avatar
Brendan Shoreland
Posts: 11
Joined: Sat Oct 27, 2018 7:34 pm
Has thanked: 11 times
Been thanked: 11 times

A tidal range on region water

Post by Brendan Shoreland »

My human lives in Plymouth UK, where, if you head due south, you are bound to encounter large quantities of seawater. One of the most interesting features of this water is that it goes up and down frequently, regularly and predictably, making significant changes to the landscape as it does so. People who live inland frequently forget this, which is why a service needs to be provided to rescue visitors who are in imminent danger of drowning.

Ever since I began subscribing to Kitely, it’s bothered me that the ocean around my island is flat and unchanging. I looked around for a tidal range script and discovered that there wasn’t one to be found. With some help from Krull Kitty, I tried to develop one, but nothing worked. So, I thought about it. For a year.

I decided to base the script on sun position.z and assumed that it's a linear progression ranging from -1.000000 to 1.000000. It isn’t. So, I sat on a rock in Kitely for two hours and noted the sun position.z figure every 2-1/2 minutes. A tidal range of around five metres felt about right, approximating the Bristol Channel, due north of Plymouth.

O.5m increments looked jarringly obvious, so I opted for 0.25m increments, even though it doubled the number of steps. There are “slack “ periods at the top and bottom of each tide, so I’ve reflected those.

I developed a script that rises and falls twice every Kitely (4 hour) day, with a range from 13.75m to 19.00m in 0.25m increments every 2-1/2 minutes. I’ve tested it on ReGen (which you are welcome to visit and watch) and it appears to be working exactly as I’d hoped. Simply drop the script into a convenient rock and off it goes. If you want it to stop, just delete it again. The tide isn’t something you can switch on and off!
I do know that incorporating the script drove me to a frenzy of terraforming for a while. Some areas, particularly river beds and shorelines, just didn’t look right as they drained. But now I have an island that looks and feels more like home!

Code: Select all

// This script adjusts the Region Water Height between 13.75m & 19.00m in 0.25m increments at 2-1/2 minute intervals.
// It's designed to run continuously, creating two high tides and two low tides per Kitely day.

default {
   state_entry() {
      llSetTimerEvent(10);
   }
   timer() {
      vector sun = llGetSunDirection();
         if(sun.z >=0.997912 & sun.z <=1.000000) osSetRegionWaterHeight(19.00);
         if(sun.z >=0.991539 & sun.z <=0.997911) osSetRegionWaterHeight(19.00);
         if(sun.z >=0.980909 & sun.z <=0.991538) osSetRegionWaterHeight(18.75);
         if(sun.z >=0.966069 & sun.z <=0.980908) osSetRegionWaterHeight(18.75);
         if(sun.z >=0.947080 & sun.z <=0.966068) osSetRegionWaterHeight(18.50);
         if(sun.z >=0.924026 & sun.z <=0.947079) osSetRegionWaterHeight(18.25);
         if(sun.z >=0.897005 & sun.z <=0.924025) osSetRegionWaterHeight(18.00);
         if(sun.z >=0.866133 & sun.z <=0.897004) osSetRegionWaterHeight(17.75);
         if(sun.z >=0.831543 & sun.z <=0.866132) osSetRegionWaterHeight(17.50);
         if(sun.z >=0.793380 & sun.z <=0.831542) osSetRegionWaterHeight(17.25);
         if(sun.z >=0.751817 & sun.z <=0.793379) osSetRegionWaterHeight(17.00);
         if(sun.z >=0.707031 & sun.z <=0.751816) osSetRegionWaterHeight(16.75);
         if(sun.z >=0.663921 & sun.z <=0.707030) osSetRegionWaterHeight(16.50);
         if(sun.z >=0.618480 & sun.z <=0.663920) osSetRegionWaterHeight(16.25);
         if(sun.z >=0.570870 & sun.z <=0.618479) osSetRegionWaterHeight(16.00);
         if(sun.z >=0.522940 & sun.z <=0.570869) osSetRegionWaterHeight(15.75);
         if(sun.z >=0.471556 & sun.z <=0.522939) osSetRegionWaterHeight(15.50);
         if(sun.z >=0.418517 & sun.z <=0.471555) osSetRegionWaterHeight(15.25);
         if(sun.z >=0.364010 & sun.z <=0.418516) osSetRegionWaterHeight(15.00);
         if(sun.z >=0.308227 & sun.z <=0.364009) osSetRegionWaterHeight(14.75);
         if(sun.z >=0.251360 & sun.z <=0.308226) osSetRegionWaterHeight(14.50);
         if(sun.z >=0.193613 & sun.z <=0.251359) osSetRegionWaterHeight(14.25);
         if(sun.z >=0.135184 & sun.z <=0.193612) osSetRegionWaterHeight(14.00);
         if(sun.z >=0.076282 & sun.z <=0.135183) osSetRegionWaterHeight(13.75);
         if(sun.z >=0.004736 & sun.z <=0.076281) osSetRegionWaterHeight(13.75);
         if(sun.z >=-0.067037 & sun.z <=0.004735) osSetRegionWaterHeight(13.75);
         if(sun.z >=-0.138467 & sun.z <=-0.067038) osSetRegionWaterHeight(14.00);
         if(sun.z >=-0.209184 & sun.z <=-0.138468) osSetRegionWaterHeight(14.25);
         if(sun.z >=-0.278821 & sun.z <=-0.209185) osSetRegionWaterHeight(14.50);
         if(sun.z >=-0.347021 & sun.z <=-0.278822) osSetRegionWaterHeight(14.75);
         if(sun.z >=-0.413429 & sun.z <=-0.347022) osSetRegionWaterHeight(15.00);
         if(sun.z >=-0.477706 & sun.z <=-0.413430) osSetRegionWaterHeight(15.25);
         if(sun.z >=-0.539519 & sun.z <=-0.477707) osSetRegionWaterHeight(15.50);
         if(sun.z >=-0.598548 & sun.z <=-0.539520) osSetRegionWaterHeight(15.75);
         if(sun.z >=-0.654495 & sun.z <=-0.598549) osSetRegionWaterHeight(16.00);
         if(sun.z >=-0.707065 & sun.z <=-0.654496) osSetRegionWaterHeight(16.25);
         if(sun.z >=-0.751862 & sun.z <=-0.707066) osSetRegionWaterHeight(16.50);
         if(sun.z >=-0.793425 & sun.z <=-0.751863) osSetRegionWaterHeight(16.75);
         if(sun.z >=-0.831581 & sun.z <=-0.793426) osSetRegionWaterHeight(17.00);
         if(sun.z >=-0.865073 & sun.z <=-0.831582) osSetRegionWaterHeight(17.25);
         if(sun.z >=-0.897036 & sun.z <=-0.865074) osSetRegionWaterHeight(17.50);
         if(sun.z >=-0.923216 & sun.z <=-0.897037) osSetRegionWaterHeight(17.75);
         if(sun.z >=-0.946400 & sun.z <=-0.923217) osSetRegionWaterHeight(18.00);
         if(sun.z >=-0.965520 & sun.z <=-0.946401) osSetRegionWaterHeight(18.25);
         if(sun.z >=-0.980496 & sun.z <=-0.965521) osSetRegionWaterHeight(18.50);
         if(sun.z >=-0.991261 & sun.z <=-0.980497) osSetRegionWaterHeight(18.75);
         if(sun.z >=-0.997772 & sun.z <=-0.991262) osSetRegionWaterHeight(18.75);
         if(sun.z >=-1.000000 & sun.z <=-0.997773) osSetRegionWaterHeight(19.00);
     }
}
There is probably an equation that could have reduced the script to three steps. If there is, it’s beyond me, but I’d be delighted to hear about anything that streamlines or refines the process. From what I can see, the script makes almost no demand on CPU or packet performance. Since it’s running whenever ReGen is opened, it would be important to know if anyone has reason to disagree with me.

There is a further issue when I noticed that I was regularly drowning the swan floating on the pond in front of our house. So I cobbled together a further script to be inserted into any object that should be floating on the surface of region water.

Code: Select all

// A script to be used in conjunction with "Tidal range adjusting region water height" script
// To be inserted into any object that should float on region water 

default
{
    state_entry()
    {llSetTimerEvent(2.0);}
 
    timer()
    {
        vector vTarget = llGetPos();
        vTarget.z = llGround( ZERO_VECTOR );
        float fWaterLevel = llWater( ZERO_VECTOR );
        if( vTarget.z < fWaterLevel )
        {
            vTarget.z = fWaterLevel;
        }
        llSetRegionPos(vTarget + <0,0,0.1>);  //alter the z quantity to adjust object buoyancy
        llResetScript();
        state Ground;
    }
}
Once again, any suggestions for improvements would be appreciated.
These users thanked the author Brendan Shoreland for the post (total 5):
Ilan TochnerGraham MillsShandon LoringTess JuelTonia Kara 3
User avatar
Shandon Loring
Posts: 1346
Joined: Sat Oct 26, 2013 3:25 am
Has thanked: 972 times
Been thanked: 1586 times
Contact:

Re: A tidal range on region water

Post by Shandon Loring »

That is superiorly fantastically cool!!
Will give this a go on one our regions asap!!

APPLAUSE!!!!
These users thanked the author Shandon Loring for the post:
Brendan Shoreland
Post Reply