User Tag List

Results 1 to 4 of 4

Thread: getting unexpected trigonometric equation results

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Volnaiskra's Avatar
    Join Date
    Jan 2014
    Location
    www.sprykegame.com
    Posts
    2,548
    Mentioned
    133 Post(s)
    Tagged
    0 Thread(s)

    Question getting unexpected trigonometric equation results

    I'm using the following equation that I found on Stack Overflow. It's supposed to convert any angle (0-360˚) into a range of -90˚ to 90˚:

    Code:
    asin(sin(angle * PI/180.0)) * 180.0/PI


    When I plug it into Excel, it works as expected. For example, you can see it converts 240 into -60:






    But when I try and use it in Fusion, it no longer constrains the answer to between -90˚ and 90˚. In fact, it just outputs the input back at me (so 240 becomes 240):





    What am I doing wrong?

  2. #2
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,380
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    -90˚ to 90˚?
    That's only a range of 180˚. The stackflow post is talking about -180˚ to 180˚, which makes a lot more sense, and could be solved with a simple statement using "modulus" (better for performance, as trig functions are relatively expensive).

    A = ((A + 360) % 360) - 180

  3. #3
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,380
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    As for the trig formula not working - Excel uses radians, whereas CF2.5 uses degrees. The " *180 / Pi" part is how you convert between the two. If you remove that and just say: ASin(Sin( Angle )) ...it will give the same result as Excel.

  4. #4
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Volnaiskra's Avatar
    Join Date
    Jan 2014
    Location
    www.sprykegame.com
    Posts
    2,548
    Mentioned
    133 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MuddyMole View Post
    -90˚ to 90˚?
    That's only a range of 180˚. The stackflow post is talking about -180˚ to 180˚, which makes a lot more sense, and could be solved with a simple statement using "modulus" (better for performance, as trig functions are relatively expensive).

    A = ((A + 360) % 360) - 180
    The post was asking for -180˚to 180˚, but one of the answers mistakenly provided a solution for -90˚ to 90˚. The author later updated the answer to produce -180˚ to 180˚, but kept the old answer in place too...luckily for me, since -90˚ to 90˚ is what I was actually after.

    If you're wondering why I would want to convert 360˚ to -90˚ to 90˚, it's for a horizontally-flying enemy that I want to tilt towards the player when it chases the player. So, regardless whether it's travelling left or right, it should either tilt down towards 90˚, or up towards -90˚. Of course, in reality, tilting downwards in Fusion requires increasing angle if travelling left or decreasing it if travelling right, but I already adjust for this elsewhere in my code. So for my purposes, I just need the equation to give me 0˚ to 90˚ if tilting down or 0 to -90˚ if tilting up. It should never go beyond abs(90) as that would no longer be a tilt but would actually change X direction. I also have code already in place elsewhere that will make the enemy change X direction if need be, so for my purposes in this section the tilt must not exceed abs(90).

    I'm not concerned about performance in this instance, as enemies will only perform this check once or twice a second, and even then only if they're within close proximity to the player.

    Quote Originally Posted by MuddyMole View Post
    As for the trig formula not working - Excel uses radians, whereas CF2.5 uses degrees. The " *180 / Pi" part is how you convert between the two. If you remove that and just say: ASin(Sin( Angle )) ...it will give the same result as Excel.
    Fantastic. Thanks very much! That explains it, and it works perfectly now. And ditching the ...PI/180.0)) * 180.0/PI... part makes the equation a lot less cumbersome, which is a nice bonus.

Similar Threads

  1. Android Unexpected translucent backdrop
    By springthunder in forum HTML5 Export Module 2.5
    Replies: 1
    Last Post: 30th March 2019, 04:49 PM
  2. [BUG/Unexpected Behaviour] NOT Overlapping an object
    By netninja in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 26th April 2012, 07:15 AM
  3. Trigonometric walk cycle
    By ELCGames in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 30th April 2011, 05:48 PM
  4. Project and unexpected closing of subapps
    By Tiny in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 28th January 2011, 01:56 PM
  5. Unexpected crash
    By Nifflas in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 25th February 2009, 03:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •