Rotating objects?

  • #1, by EinzelkämpferWednesday, 01. April 2015, 10:51 9 years ago
    The thread title says it all: is there a way of rotating objects (other than having a prerendered animation)?

    If not: WHY NOT? wink

    Newbie

    81 Posts


  • #2, by SimonSWednesday, 01. April 2015, 10:57 9 years ago
    In the newest version there is. But you need to use lua.

    Objects.object.Rotation = 1.5
    

    Thread Captain

    1580 Posts

  • #3, by EinzelkämpferWednesday, 01. April 2015, 11:16 9 years ago
    Sounds great. And Lua is okay.

    And now, by having another look at the wiki, I find "ObjectRotation" and "ObjectRotationCenter" in the data structure. Stupid me. I had looked at the commands pages only. *handvordiestirnklatscht*

    So this question can be considered answered... and unnecessary. confuse Thank you.

    Newbie

    81 Posts

  • #4, by afrlmeWednesday, 01. April 2015, 11:23 9 years ago
    Quick note about rotation. Don't try to rotate objects that go outside of the viewport (current section of scene that is shown) as it crops the image that is outside of camera which ends up screwing up the object rotation center. Simon said he would fix this for future build, but I don't know whether he has gotten around to it or not.

    Imperator

    7278 Posts

  • #5, by EinzelkämpferWednesday, 01. April 2015, 11:58 9 years ago
    Thank you. I will keep that in mind (and probably complain about it to the developers later twist ).

    Newbie

    81 Posts

  • #6, by afrlmeWednesday, 01. April 2015, 13:25 9 years ago
    Here's a quick example of a tween rotation. In this example I'm rotating an asteroid 360º over 60 seconds. I've enabled loop & set it so that it doesn't rotate in reverse after playing forward. I set easeLinearInOut as easing because I wanted the speed to remain constant.
    local obj = game.CurrentScene.SceneObjects["asteroid"]
    --obj.Scale = 0.5 -- is possible to define initial scale of object sprite / active animation
    obj.RotationCenter = { x = -1, y = -1} -- -1, -1 = center of sprite / animation, define other coordinates if you don't want it to rotate via center.
    
    obj:to(60000, {Rotation = math.rad(360)}, easeLinearOut, true, false) -- new to() tween function (simpler than startObjectTween function, however may not work in current public build).
    

    ... the to() function may not work in the current public build. I'm using a team build I got from David yesterday. Oh by the way I used math.rad(360) to define the degrees because rotation field uses radian value instead of degrees. math.rad() returns the converted degree to radian value.

    Imperator

    7278 Posts

  • #7, by EinzelkämpferWednesday, 01. April 2015, 13:44 9 years ago
    Oh, great. That may come in handy. Thanks a lot.

    I could try the to() function with MY latest team build however (although not quite as up-to-date as yours)... grin

    Newbie

    81 Posts

  • #8, by afrlmeWednesday, 01. April 2015, 14:02 9 years ago
    if it's from at least february, then the to() function should work ok I think.

    Imperator

    7278 Posts

  • #9, by EinzelkämpferWednesday, 01. April 2015, 14:36 9 years ago
    It's from January, but it works. smile

    Don't try to rotate objects that go outside of the viewport [...] Simon said he would fix this for future build, but I don't know whether he has gotten around to it or not.

    No, he obviously hasn't.

    EDIT: To clarify things. The object may go outside the viewport while rotating. That works fine and nothing is cropped. But if the screen is larger than the viewport and the character starts moving (making the screen scroll), the rotating object goes nuts. In my case this doesn't matter however.

    Newbie

    81 Posts

  • #10, by afrlmeWednesday, 01. April 2015, 15:15 9 years ago
    Hmm. For me if the object is part outside / inside the scene, regardless of scene background size, it cuts away the part of the sprite that's outside of the viewport & thus the center is now defined based on what can be seen on screen. So what I end up with is the part of the asteroid I can see with a right angle section cut out of it, which looks a bit crazy rotating around the bottom left corner of the scene.

    By the way rotation should only be applied to images / animations that are dead on flat / center to the screen, seeing as they are 2D & not 3D. If you want to rotate a scene object with a 3D perspective, then create it as a 3D model & add it as a character to the 3D character section. I believe it is possible to control the perspective camera from the 3D model & the rotation / direction of it, although not 100% sure as I'm not too savvy on the 3D stuff.

    Imperator

    7278 Posts

  • #11, by EinzelkämpferWednesday, 01. April 2015, 15:56 9 years ago
    Ah, I see. You are right. Objects that are partly outside the screen from the beginning are cropped indeed. I had tried with an object that is inside the screen but partly (or completely) outside during rotation only. I thought that would be the problem, but fortunately it is not. So objects can leave the viewport while rotating and will come back without damage.

    2D is okay in this case. My object is round and centered. Like a Monkey Island code wheel. grin

    Newbie

    81 Posts