Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
What is perfect number to setAngle() to get 1 degrees? — Gideros Forum

What is perfect number to setAngle() to get 1 degrees?

JalapenodevJalapenodev Member
edited March 2014 in General questions
I have now this like code:

function onTimer(event)
body:setAngle(body:getAngle() + 0.06981310179)
end

timer = Timer.new(10, 45)
timer:addEventListener(Event.TIMER, onTimer, timer)
timer:start()

So it runs onTimer 45 times. It turns 180 degrees on every run, but when i run it like 200 times, the body is like 1 degrees in wrong angle, if i do it 1000 times it can be couple of degrees in wrong angle.

So whats perfect "1 degree" number to setAngle()?

Comments

  • amaximovamaximov Member
    edited March 2014
    try body:setAngle(body:getAngle() + math.pi/180)

    or make a variable body.rotation = 0. then simply do body.rotation = body.rotation + 1 on each timer event, and do body:setAngle(math.rad(body.rotation))

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    edited March 2014
    As those are floating numbers I don't know if you can set them so precise, but how about:
    local deg1 = math.rad(1)
     
    function onTimer(event)
     body:setAngle(body:getAngle() + deg1)
     end
     
     timer = Timer.new(10, 45)
     timer:addEventListener(Event.TIMER, onTimer, timer)
     timer:start()
    Or rounding like:
    function onTimer(event)
     body:setAngle(math.rad(math.floor(math.deg(body:getAngle()) + 1)))
     end
     
     timer = Timer.new(10, 45)
     timer:addEventListener(Event.TIMER, onTimer, timer)
     timer:start()
  • JalapenodevJalapenodev Member
    edited March 2014
    try body:setAngle(body:getAngle() + math.pi/180)

    or make a variable body.rotation = 0. then simply do body.rotation = body.rotation + 1 on each timer event, and do body:setAngle(math.rad(body.rotation))
    That first one worked just as perfect and simple I was hoping.

    Thank you!

  • Hold them in a variable as degrees, then when setting the rotation just turn them in to a rad at the same time - this way you can just increment your local variable by one.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.