Advertisement
Kijan

rotate to multiple of 30

May 30th, 2020
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. rotate30(planeObject)
  2.  
  3. use this after you rotated an object. if you put it on an object that should rotate use self in the brackets if you use it on global use planeObject if you put it to the rotations.
  4.  
  5.  
  6.  
  7.  
  8.  
  9. -- this is the function to rotate it to the correct multiple of 30 foir all three values x, y, z
  10. -- you have to wait a frame and then to wait for the object to rest before using it else oyu have wrong rotation values.
  11. -- this is probably the reson why you get non multiple of 30 because you pressed it to fast, while still rotating.
  12. -- so the new rotation starts when the old is still running. maybe ;)
  13.  
  14. function rotate30(obj)
  15.    Wait.frames(
  16.       function()
  17.          Wait.condition(
  18.             function()
  19.                local rot = obj.getRotation()
  20.                local rot30 = 0
  21.                for k, v in pairs(rot) do
  22.                   rot30 = v%30
  23.                   if rot30 ~= 0 then
  24.                      if rot30 < 15 then
  25.                         rot[k] = v - v%30
  26.                      else
  27.                         rot[k] = v + 30 - v%30
  28.                      end
  29.                   end
  30.                end
  31.                obj.setRotation(rot)
  32.             end,
  33.             function() return obj.resting end,
  34.          5)
  35.       end,
  36.    1)
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement