[SOLVED] Rotate Animation Script question

  • #1, by sebastianWednesday, 10. May 2017, 20:10 7 years ago
    Hey there dudes and dudettes,

    the recently posted "Rotate Animation" Script is great! It allows me to animate stuff like grass or banners neatly: ( http://www.visionaire-studio.com/luadocs/#rotate-animation )

    The function i use is
    setRotateAnimation(object, speed, offset, strength, direction, func)

    I'd like to use different functions now to "animate" different objects in the scene.

    What possible functions are available for the "func" attribute?

    Also (question2):
    I like graphics.noise a lot, but all noises seem to be the same. Is there an option to choose a different "noise" or if using math.sin to use different positions in this to simulate some kind of wind / breeze from left to right going through the differents objects?

    EDIT: wait.... does the "offset" setting do this?
    EDIT2: yes it was.... SO question 2 is answered smile

    Thanks in advance

    Sebastian

    Thread Captain

    2346 Posts


  • #2, by stroncisWednesday, 10. May 2017, 21:52 7 years ago
    First, to clarify things up - this is shader based fx. Some options can be set to negative values, that comes very true for offset. Pass mouse coordinates to it, making from -5.0 to +5.0 with 0.0 at the screen center and you will control direction of wind with mouse.

    Speed - obvious
    Offset - is more like wind direction strength in this case, object bending angle.
    Strength - wind strength
    Direction - root position
    Func - this is the vibration pattern, which can be programmed. garphics.noise and garphics.noise2 are perlin noises and thus are just noises, you can't make them to behave in some intricate manner. If you want something in particular like wind gusts with specific vibration patterns, then there's math involved and some external input, which controls wind strength and this funcion in cooperation.

    Newbie

    42 Posts

  • #3, by sebastianWednesday, 10. May 2017, 21:58 7 years ago
    Func - this is the vibration pattern, which can be programmed. garphics.noise and garphics.noise2 are perlin noises and thus are just noises, you can't make them to behave in some intricate manner. If you want something in particular like wind gusts with specific vibration patterns, then there's math involved and some external input, which controls wind strength and this funcion in cooperation.
    allright... so there are "only" two builtin functions here graphics.noise and graphics.noise2?
    Any ideas how to do own stuff here? Im not sure what the rotateion script needs the "func" 
    return to make use of it.


    Thread Captain

    2346 Posts

  • #4, by stroncisWednesday, 10. May 2017, 22:23 7 years ago
    Basically you can write any function (even use inputs like time, mouse) which returns floating value between 0 and 1.0. In my example input is from mouse, so wiggle it and you'll get wind!
    function()return getCursorPos().x / game.WindowResolution.x end

    In this example, i get mouse position as integer, then i divide it by game window width. This way i get floating value from 0.0 to 1.0, which perfectly works for demonstration, what actually happens, when graphics.noise or sin() spitting away, just in high frequency and variation in value.

    Newbie

    42 Posts

  • #5, by sebastianWednesday, 10. May 2017, 22:31 7 years ago
    Basically you can write any function, even use time, which returns floating value, but I don't know what range is, maybe between 0 and 1.0.

    function()return getCursorPos().x * 1 / game.WindowResolution.x end

    aaaaahhh... now i understand. It needs to be a function because it gets called every time. It cant be just a value or some static stuff because then it doesn't move...
    Time to get schwifty

    Thread Captain

    2346 Posts

  • #6, by stroncisWednesday, 10. May 2017, 22:35 7 years ago
    Yes, exactly, and then this value is passed to shader.

    Newbie

    42 Posts

  • #7, by constantinThursday, 11. May 2017, 10:37 7 years ago
    can someone explain, how this script can be used? 

    Forum Fan

    167 Posts

  • #8, by ke4Thursday, 11. May 2017, 10:44 7 years ago
    Sebastian could you please post some example gif?

    Key Killer

    810 Posts

  • #9, by sebastianThursday, 11. May 2017, 10:48 7 years ago
    can someone explain, how this script can be used? 

    Hey Constantin,



    into your scripts workspace as a definition script.

    Then you can use the functions mentioned in the first link to "animate" e.g. tree branches in the wind or some banners hanging from the ceiling.

    I used a function in the scene action "at beginning of scene" and started an "execute script" action part doing this:


    setRotateAnimation(Objects["gfx_banner_left_1"], 0.4, 1, 0.1, 2, graphics.noise)
    setRotateAnimation(Objects["gfx_banner_left_2"], 0.3, 3, 0.2, 2, graphics.noise)
    setRotateAnimation(Objects["gfx_banner_left_3"], 0.4, 5, 0.15, 2, graphics.noise)
    

    this will rotate the objects image based on the graphics.noise function with the top edge (2) fixed, so that the top stays still and to the bottom bounces a bit.


    Further examples in the script itself:


    -- Rotate Animations
    --
    -- Examples:
    -- setRotateAnimation(Objects["2040_Bush_light_17"], 1.0, 0.3, 0.2, 3, graphics.noise)
    -- setRotateAnimation(Objects["2040_Tree_b_light_01"], 1.0, 0.0, 0.2, 3, math.sin)
    -- setRotateAnimation(Objects["2040_VG2"], 1.0, 0.0, 0.2, 3, function(a)return math.sin(graphics.noise(a)) end)
    --
    -- setRotateAnimation(object, speed, offset, strength, direction, func)
    -- func can be: function(a)return math.sin(graphics.noise( a )) end
    -- setRotateAnimationToStrength(objectnamestring, speed, offset, strengthFrom, strengthTo, direction, function, time) -> smooth Rotation From - To Strength
    -- direction/pinned side:
    -- 1 - down, 2 - up, 3 - left, 4 - right
    --

    PS: @devs: how do i stop such animations razz?

    Thread Captain

    2346 Posts

  • #10, by ke4Thursday, 11. May 2017, 11:16 7 years ago
    Thanks Sebastian. I imaginaded something else under the function. More like a complete rotation. But that can be achieved by the :to() function and Rotation field.

    Well this is indeed nice feature for some wind effect. Any other ideas how to put it in use?

    Key Killer

    810 Posts

  • #11, by afrlmeThursday, 11. May 2017, 12:21 7 years ago
    Interesting. Looks like this could be quite useful. Have you tried using it on higher resolution graphics with more detail?

    Imperator

    7278 Posts