Object rotation

  • #1, by AlzasTuesday, 21. October 2014, 09:36 10 years ago
    Hello everyone.

    After a little search here in the forums it seems that there is no action part to help us rotate an object of a scene. Does anyone know a simple way to rotate the image of an object, for example a wheel, on a mouse click?

    Newbie

    21 Posts


  • #2, by afrlmeTuesday, 21. October 2014, 11:59 10 years ago
    I'm not sure if Alex plans on creating a rotate object/image/animation action part but support for rotation has already been added to the engine & can be done via lua script. Here is a workflow function I created based on the example Simon provided me.

    -- note: reverse only works if loop is enabled. (reverse means play forward then backwards)
    -- note: loop amount can be increased by adding higher rotation value. i.e: 720 will rotate 2x
    -- note: rotation can also be done in the opposite direction by using a negative value. i.e: -180
    -- example:  rotateObject("granny", 100, 170, 3000, easeQuintOut, false, false)
    
    function rotateObject(obj, scale, degree, delay, easing, reverse, loop)
     obj = Objects[obj]
     obj.RotationCenter = {x = -1, y = obj.ObjectSprite.SpriteSprite:getPosition().y}
     obj.Rotation = obj.Rotation; obj.Scale = obj.Scale
     scale = (scale / 100) -- convert scale percent to decimal
     degree = (degree * math.pi) / 180 -- convert degree to radian
     obj:to(delay, {Rotation = degree, Scale = scale}, easing, loop, reverse)
    end
    

    Imperator

    7278 Posts

  • #3, by AlzasTuesday, 21. October 2014, 13:03 10 years ago
    Thanks a lot AFRLme. I will give it a try when i get home.

    Cheers.

    Newbie

    21 Posts

  • #4, by blink3dSaturday, 11. April 2015, 07:02 9 years ago
    Hello, AFRLme.

    First of all thank you for the script, it works like magic.
    I just got one problem, i do not have any programming knowledge, so i stay away from messing up the code.

    So here is the issue.
    When i used the function, the targeted object rotates successfully but when i click on it again it doesn't rotate, object remains still.

    If you click on it, it should rotate once, if you click on it again it should rotate to next position.

    Can you please tell me, how can i achieve that. I tried using the inbuilt function "position animation" but it just accepts "x" and "y" positions, no degrees.

    Thanks again.

    Newbie

    22 Posts

  • #5, by afrlmeSaturday, 11. April 2015, 12:21 9 years ago
    A'llo... Check out http://www.visionaire-studio.net/forum/thread/cyclepuzzle/1/

    P.S: ignore my code for getting rotation center. The values should just be set to x = -1, y = -1, as -1, -1 will automatically rotate from center of the image.

    Imperator

    7278 Posts

  • #6, by blink3dSaturday, 11. April 2015, 22:03 9 years ago
    Hi, AFRLme,

    I stopped messing up with the code, and decided to take long and hard way. I took the "CyclePuzzle.zip" project and its files to experiment with.

    First of all,
    i removed all the scripts and scenes and began with new one,
    made all the required animations frames with help adobe flash, (this didnt take much time; instead increased the folder size).

    By just using if statements and your help, i was able to achieve what i was seeking. It took me about 3-4 hours.

    Please check, and give feedback, and any ideas to make it more compact.

    Newbie

    22 Posts

  • #7, by afrlmeSunday, 12. April 2015, 00:04 9 years ago
    Damn, that sure looks like a long winded approach. I think I prefer my script method. It required considerably less work than your method. I could have had it rotate the images like you did, but the shape of the image in Unreal's .ved wasn't really ideal.

    P.S: I believe that my .ved example & script example may not work for you correctly. I used functions & shorthand Lua code, that may not be available in the public build of Visionaire Studio. I often use team builds, when they are provided to me & they often have various new features & bug fixes.

    Imperator

    7278 Posts

  • #8, by blink3dSunday, 12. April 2015, 07:34 9 years ago
    cry

    Newbie

    22 Posts

  • #9, by afrlmeSunday, 12. April 2015, 12:15 9 years ago
    Sure, your method worked. But look at all the if queries, action parts & animations you needed to use. & that was only for one direction & one ring at a time.

    My small script / functions worked for both directions & affected multiple rings. The inner ring moved on its own. The middle ring affected both the middle & outer ring & I think the outer ring affected all 3 (but I can't remember off the top of my head).

    Anyway... my point is: just imagine if you had to do all that work each time you wanted to do a ring / rotation puzzle.

    Imperator

    7278 Posts

  • #10, by blink3dSunday, 12. April 2015, 15:22 9 years ago
    True, true. It's not really a smart idea, to take that long route unless you are desperate or you have to do it cause its main feature of the game.

    Double the work, double the time, double the project size.

    Can you please provide me the project file where the script is working. I must have done something wrong on my side. I would be grateful if you do.

    Newbie

    22 Posts

  • #11, 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