Object rotation

  • #10, by afrlmeSunday, 12. April 2015, 15:42 9 years ago
    What was happening in the project in the thread I linked?

    The link to my project files was in the 5th message. https://www.dropbox.com/s/tbm3v3p0zf0zjw1/CyclePuzzle.zip?dl=0

    I used the to() tween function which doesn't always work in the current public build.

    It's a little hard to explain my code but here it is. Basically I created a table with the different rotation degrees that the rings could be set to. Then I create a function to randomize the initial degree of each ring. Next I wrote a function which checks current degree of the selected ring & then rotates it forwards or backwards depending on the function called in an execute a script file. Then the rest are functions for checking if puzzle is correct on each rotation.
    --[[
    Rotation Puzzle 001 [V1] (03/02/2015)
    Written by AFRLme [Lee Clarke]
    -- + --
    afrlme@outlook.com | skype @ AFRLme
    -- + --
    This script is donation optional. In game credit is non-negotiable.
    You are free to: ¹ use it in your game(s). ² modify the script.
    Do not remove - or edit - this comment block.
    --]]
    
    -- * variables * --
    local size, pos
    
    -- * tables * --
    local t = {0, 60, 120, 180, 240, 300}
    
    -- * function which rotates the tiles * --
    function rotateObject(obj, delay, direction)
     obj = Objects[obj]
     obj.RotationCenter = { x = -1, y = -1 }
     obj.Rotation = obj.Rotation
     if direction then
      if math.floor(math.deg(obj.Rotation)) == 0 or math.ceil(math.deg(obj.Rotation)) == 0 then obj:to(delay, {Rotation = math.rad(60)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 60 or math.ceil(math.deg(obj.Rotation)) == 60 then obj:to(delay, {Rotation = math.rad(120)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 120 or math.ceil(math.deg(obj.Rotation)) == 120 then obj:to(delay, {Rotation = math.rad(180)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 180 or math.ceil(math.deg(obj.Rotation)) == 180 then obj:to(delay, {Rotation = math.rad(240)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 240 or math.ceil(math.deg(obj.Rotation)) == 240 then obj:to(delay, {Rotation = math.rad(300)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 300 or math.ceil(math.deg(obj.Rotation)) == 300 then obj:to(delay, {Rotation = math.rad(0)}, easeLinearOut)
      end
    else
      if math.floor(math.deg(obj.Rotation)) == 0 or math.ceil(math.deg(obj.Rotation)) == 0 then obj:to(delay, {Rotation = math.rad(300)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 60 or math.ceil(math.deg(obj.Rotation)) == 60 then obj:to(delay, {Rotation = math.rad(0)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 120 or math.ceil(math.deg(obj.Rotation)) == 120 then obj:to(delay, {Rotation = math.rad(60)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 180 or math.ceil(math.deg(obj.Rotation)) == 180 then obj:to(delay, {Rotation = math.rad(120)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 240 or math.ceil(math.deg(obj.Rotation)) == 240 then obj:to(delay, {Rotation = math.rad(180)}, easeLinearOut)
       elseif math.floor(math.deg(obj.Rotation)) == 300 or math.ceil(math.deg(obj.Rotation)) == 300 then obj:to(delay, {Rotation = math.rad(240)}, easeLinearOut)
      end
     end
    end
    
    -- * function which randomizes tile degrees at begin of scene * --
    function initPzl_1(obj)
     for i = 1, 3 do
      -- + --
      obj = Objects["pzl-001_"..i]
      obj.RotationCenter = { x = -1, y = -1 }
      obj.Rotation = obj.Rotation
       -- + --
      obj:to(0, { Rotation = math.rad( t[math.random(6)] ) }, easeLinearOut)
     end
    end
    
    -- * function which checks if tiles rotation value is 0 * --
    function checkPzl_1(o)
     if math.floor(math.deg(Objects[o].Rotation)) == 0 or math.ceil(math.deg(Objects[o].Rotation)) == 0 then
      return true
     end
    end
    

    ... This script is just for that particular puzzle. A new script would need to be created for each puzzle, well unless I could come up with something a bit more global. But either way, it's much less work than using action parts. However rotating images may not be possible depending on the puzzle & the perspective of the scene / puzzle, because rotation requires the images to be flat to the screen to rotate correctly, seeing as it's 2D & not 3D.

    In other words, any method you use, will be complicated & cumbersome, but puzzles are never that straight forward to make anyway! wink

    Imperator

    7278 Posts


  • #11, by blink3dSunday, 12. April 2015, 16:16 9 years ago
    Ohh my god..

    I just checked again, its not running well. Whenever i click on the rings they appear somewhere else. I guess its the bug in the build which i am using.

    Thank you so much AFRLme. Constant support is remark less. I am really happy to see these quick responses from this forum. I don't know if you remember. I am studying right now to become a Game Designer. And currently working on a adventure game. Will show you the game, when its in proper condition. More queries will be coming up, if i have any doubt winkrazz

    Thanks again.

    Newbie

    22 Posts

  • #12, by afrlmeSunday, 12. April 2015, 16:35 9 years ago
    Remember? I have short term memory. I barely remember 1 day to the next! grin

    No problem. The example I linked should work just fine in the next public build.

    Imperator

    7278 Posts

  • #13, by LebosteinMonday, 18. May 2015, 12:27 9 years ago
    What is the best way to control the speed of an eternally rotated object? A have tried to rotate an object in a very simple way:
    wheel = Scenes["room_mill_outside"].Objects["gfx_waterwheel"]
    
    function rotateWheel()
        wheel.Rotation = wheel.Rotation + 0.01
        if wheel.Rotation > 2 * math.pi then wheel.Rotation = wheel.Rotation - 2 * math.pi end
    end
    
    registerEventHandler("mainLoop", "rotateWheel")
    

    I need to call the rotateWheel() function only some times per second (in dependence of the needed speed and the given delta angle). How I can handle this? At the moment my delta angle is very small (0.01 radian) because the function is called in every engine loop.

    Key Killer

    621 Posts

  • #14, by afrlmeMonday, 18. May 2015, 14:16 9 years ago
    Why not create a called by other action & use the jump to x action part inside of it to create the loop, then use the regular method of rotation using the tween functions & a random value to determine the pause time between loops & the amount of time it should take to rotate.

    Just out of curiosity: what is it you are intending to do?

    P.S: the mainLoop loops every 4ms or so. It's very fast. The only way to add a pause to that via Lua script is to use the os.time(), os.date() or getTime() functions to create an initial time & time passed since each loop.

    Imperator

    7278 Posts

  • #15, by LebosteinMonday, 18. May 2015, 14:25 9 years ago
    Just out of curiosity: what is it you are intending to do?

    Rotating a water mill like that:
    http://upload.wikimedia.org/wikipedia/commons/2/2a/Vodn%C3%AD_kolo.jpg
    It is an infinite rotation of a simple object image...

    Key Killer

    621 Posts

  • #16, by afrlmeMonday, 18. May 2015, 14:57 9 years ago
    As long as it's flat to the screen then you can just use the to() function wink

    in an at begin of scene function create an execute a script function & add something like this to it...
    local obj = 
    game.CurrentScene.SceneObjects["water_wheel"]
    obj.RotationCenter = {x = -1, y = -1} -- define rotation center as center of sprite
    
    obj:to(3000, {Rotation = math.rad(360)}, easeCircInOut, true, false)
    

    ... what I've written above will rotate water wheel every 3 seconds (3000ms) with a smooth-ish ease in & out & will automatically loop back to 0 when it reaches 360 degrees. All good, yes?

    Imperator

    7278 Posts

  • #17, by LebosteinMonday, 18. May 2015, 15:22 9 years ago
    Wow! Thanks. What does the parameters 3-5 (easeCircInOut, true, false) exactly? I see an acceleration of the rotation, cool effect, but I need a simple linear rotation.

    PS: There are more of such undocumented features?

    Key Killer

    621 Posts

  • #18, by afrlmeMonday, 18. May 2015, 16:02 9 years ago
    ahh ok, just change easeCircInOut to easeLinearInOut, which will pretty much keep it at a constant speed.

    Ok so here's a quick breakdown of the to() function.
    to(delay in ms, {actions, separated, by, commas}, easing, loop, reverse)
    

    ... the reverse option requires loop to be true & will perform the action forwards & then backwards in a never ending loop.

    Technically you don't actually have to add the last 3 parameters each time you use the to() function as it depends on what you are doing. If you don't need easing, looping or reverse & just want to quickly transition something over a specific amount of time, such as an objects visibility value then you can simply do something like this...
    Objects["button1"]:to(300, {Visibility = 0}) -- set button1 to 0% opacity over 300ms
    


    One word of warning though... it seems that if you access certain data structure fields using the tween functions to() or startObjectTween() that you may no longer be able to change the values using the action part methods.

    Imperator

    7278 Posts

  • #19, by LebosteinMonday, 18. May 2015, 16:21 9 years ago
    Thanks! I saw this link in a post from you on adventurefans.net:
    http://easings.net/

    This easing functions you can add to translations and visibility too for creating bouncing effects and so on. There is more potential in Visionaire as I thought...

    Key Killer

    621 Posts

  • #20, by afrlmeMonday, 18. May 2015, 16:33 9 years ago
    Yes you can easing for a lot of situations. You might want to move an object or animation to a new position in a scene & with easing you could have it gradually speed up or slow down or both. Or you could add bounce or elastic easing to an interface to have it bounce up & down when it slides out. There's loads of possibilities.

    P.S: Simon linked that easing webpage via the wiki I think. As for adventure fans... I don't actually post there. I think Thomas directly tied vs database into the adventure fans forum, so it does have its own unique content, but it also automatically takes threads from certain sections of the VS forum.

    P.P.S: there is probably more potential with VS than most people realize, which is one of the main reasons I tend to prefer approaching things with Lua script as it gives me access to features not yet implemented as action parts inside of the editor as well as access to openGL shader & the ability to write my own custom functions. With that in mind it's possible to create other game genres that VS was not meant for.

    Imperator

    7278 Posts