Check this!

About advanced scenes, and the Thyme scripting language used in Algodoo.

Check this!

Postby Luezma » Wed Aug 30, 2017 10:08 am

I made this function without really understanding what I was doing... Anyway, this function returns the smallest rotation needed to get from one angle to another, instead of using angle1 - angle2, even if they are like -3.06 and 2.5 (Algodoo would normaly go all the way from -3.06 to 2.5, but rotating in clockwise is a better option for something like angvel), this function has a range of -2π to 2π, anything else will fail. It's not finished as I can't input higher values by now.

Mr. Code
Code: Select all
angularDistanceOrWhatever := (an, gle)=>{
    a := 0;
    b := 0;
    an > math.pi ? {
        a = an - math.pi * 2
    } : {
        an <  - math.pi ? {
            a = an + math.pi * 2
        } : {a = an}
    };
    gle > math.pi ? {
        b = gle - math.pi * 2
    } : {
        gle <  - math.pi ? {
            b = gle + math.pi * 2
        } : {b = gle}
    };
    x := a - b;
    y := -(b - a - math.pi * 2);
    z := -(b - a + math.pi * 2);
    (x ^ 2) ^ 0.5 < (y ^ 2) ^ 0.5 ? {
        (x ^ 2) ^ 0.5 < (z ^ 2) ^ 0.5 ? {x} : {z}
    } : {
        (y ^ 2) ^ 0.5 < (z ^ 2) ^ 0.5 ? {y} : {z}
    }
}


You can test it on a circle with with...
Code: Select all
postStep = (e)=>{
    yeah := app.mousepos - pos;
    angvel =  - _dist(angle - math.pi / 2,  - math.aTan2(yeah(0), yeah(1)))
}
Luezma
 
Posts: 14
Joined: Thu Dec 13, 2012 7:19 pm
Location: Argentina

Re: Check this!

Postby Kilinich » Wed Aug 30, 2017 10:31 am

Too complicated.
I wrote whis one for my old AI battel scene:

Code: Select all
angleDiff := (a1, a2)=>{
    tau := (math.pi * 2);
    d := (a1 % tau - a2 % tau) % tau;
    d > math.pi ? {d - tau} : {d <  - math.pi ? {d + tau} : {d}}
}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Check this!

Postby Luezma » Fri Sep 01, 2017 1:05 am

What does % do?

*edit* Ok I know what it does, and I can't believe how simple you made it...
Luezma
 
Posts: 14
Joined: Thu Dec 13, 2012 7:19 pm
Location: Argentina


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests