1. #1
    Core2TOM's Avatar Senior Member
    Join Date
    Mar 2014
    Location
    Germany
    Posts
    506

    Math stuff

    hey guys,
    i want to rotate a object with the values from the right stick.
    how can i convert the vertical -3 to +3 and horizontal -3 to +3 values into a range from 0 to 359?



    it looks so easy on the picture but i cant get my head around it thanks!
    Share this post

  2. #2
    mutetus's Avatar Trials Developer
    Join Date
    Dec 2013
    Location
    The land of fin.
    Posts
    859
    With arctan2:
    Share this post

  3. #3
    Core2TOM's Avatar Senior Member
    Join Date
    Mar 2014
    Location
    Germany
    Posts
    506
    hey mutetus,
    no its not gonna work like that. if the horizontal value is > 0 i get values from 0 to +180 and if its < 0 i get values from 0 to -180.
    anyway now i got it to work, maybe more complicated than it has to be (?) but it works thanks for your help!

    but now i got another question if i interpolate the angle value, to get a smoother transition, the animation is like bouncing. any idea how to avoid that?
    hard to explain, here is a short vid:

    Share this post

  4. #4
    mutetus's Avatar Trials Developer
    Join Date
    Dec 2013
    Location
    The land of fin.
    Posts
    859
    Ok then does this help?

    The bottom right variable datasource has the interpolation settings, it just takes the value from the normal variable datasource.
    Share this post

  5. #5
    Core2TOM's Avatar Senior Member
    Join Date
    Mar 2014
    Location
    Germany
    Posts
    506
    hahaha whaaaaaat is this? it works perfect but i dont get it what you did there.
    im sure it has something to do with the impulse delay of 0,0166666666666667 so that i cant even see whats happening on the screen. can you try to explain how this works exactly?
    thanks <3
    Share this post

  6. #6
    mutetus's Avatar Trials Developer
    Join Date
    Dec 2013
    Location
    The land of fin.
    Posts
    859
    It's hard to explain my stuff Basically instead of taking the angle straight from the arctan2, the angle difference between the previous and current tick is calculated and added to variable that doesn't wrap around 360. The trick is in the angle difference+540 mod 360 - 180 part in the middle, which corrects the value when it wraps around 360. After setting the angle in the datasource the current angle is stored to the other datasource for next tick comparison.
    Share this post

  7. #7
    AAAAAHHH! This is exactly what I needed for something else !
    I was trying to rotate the rider using ArcTan2 smoothly but yeah, once he hit 360 degrees, he spun around in the opposite direction :P.
    Share this post