Move object action part - Make it persistent

  • #10, by ke4Wednesday, 22. March 2017, 12:35 5 years ago
    Yep you could do something like this i think

    x = (object position x – wanted position x)*-1
    y = (object position y – wanted position y)*-1

    Key Killer

    810 Posts


  • #11, by afrlmeWednesday, 22. March 2017, 12:44 5 years ago
    I bloody hate math mate. makes my head hurt.

    Imperator

    7152 Posts

  • #12, by ke4Wednesday, 22. March 2017, 12:53 5 years ago
    I bloody hate math mate. makes my head hurt.

    Haha, i guess that's why it would be handy to also have Lua absolute position option for moving objects.

    Key Killer

    810 Posts

  • #13, by afrlmeWednesday, 22. March 2017, 13:05 5 years ago
    I bloody hate math mate. makes my head hurt.

    Haha, i guess that's why it would be handy to also have Lua absolute position option for moving objects.
    Only need someone to create a workflow function with the calculations & then your all good mate. wink

    For me the math was a bastard because of the possibility of the target coordinate being a negative or positive value from the default position, which means you need to check if it's less than or more than or equal to the default x,y positions. To be honest I don't really see much point in doing it with Lua script after Alex created the "move to" action part unless you need to grab the data from a Lua table or some values. If they are predetermined positions then you could use a VS value & some if queries to check what the value is then move object to x, y or z position based on that.

    Imperator

    7152 Posts

  • #14, by ke4Wednesday, 22. March 2017, 13:17 5 years ago
    Yeah that's the issue. The acion part is nice but you can't use it dynamically with values.

    You don't actually need to check it mate. The *-1 part will take care of that.

    Let's say your object x posistion is 500, you wanted to move to 700 then
    (500 - 700)*-1 = 200

    If you would wanted to move to lower value like 150 then
    (500 - 150)*-1 = -350

    Key Killer

    810 Posts

  • #15, by afrlmeWednesday, 22. March 2017, 13:50 5 years ago
    Yeah that's the issue. The acion part is nice but you can't use it dynamically with values.

    You don't actually need to check it mate. The *-1 part will take care of that.

    Let's say your object x posistion is 500, you wanted to move to 700 then
    (500 - 700)*-1 = 200

    If you would wanted to move to lower value like 150 then
    (500 - 150)*-1 = -350
    Ah ok. I kind of guessed that the -1 value was for inversing the current value.
    function moveObj(obj, x, y, delay, easing)
     obj = game.CurrentScene.SceneObjects[obj]
     -- + --
     obj:to(delay, { ObjectOffset = {x = (obj.ObjectPosition.x - x) * -1, y = (obj.ObjectPosition.y - y) * -1} }, easing)
    end

    moveObj("rock", 500, 300, 1000, easeQuintOut)

    moveObj("rock", Values["example1"].Int, Values["example2"].Int, 1000, easeQuintOut)

    Something like that I guess?

    Imperator

    7152 Posts

  • #16, by ke4Wednesday, 22. March 2017, 14:10 5 years ago
    Well you gonna have to use ObjectPosition for that instead. The offset is gonna be 0 until you move the object.

    I guess it's getting more complicated when you want to move the object more than once since the object position won't get updated.

    I suppose you would have to check if there's any offset, if not use the method you wrote if yes then you would also need to add the current offset to the position.

    Key Killer

    810 Posts

  • #17, by afrlmeWednesday, 22. March 2017, 14:26 5 years ago
    Well you gonna have to use ObjectPosition for that instead. The offset is gonna be 0 until you move the object.

    I guess it's getting more complicated when you want to move the object more than once since the object position won't get updated.

    I suppose you would have to check if there's any offset, if not use the method you wrote if yes then you would also need to add the current offset to the position.
    Aye, you're right mate. Wrote it out quickly without thinking about it too much. Will edit the example. No, if you are moving to specific coordinates then there's no need to calculate current offset. The default object position always remains the same value.

    Imperator

    7152 Posts

  • #18, by ke4Wednesday, 22. March 2017, 14:38 5 years ago
    If the object is on x 500, you will offset it by 200 to get it on x 700 then you need to use the new position instead no? If you would want it to move more than once in a single scene visit.

    Key Killer

    810 Posts

  • #19, by afrlmeWednesday, 22. March 2017, 14:43 5 years ago
    If the object is on x 500, you will offset it by 200 to get it on x 700 then you need to use the new position instead no? If you would want it to move more than once in a single scene visit.
    ObjectPosition is always the default position value. ObjectOffset is an offset value based from the default position. So if you want to move to another specific x,y coordinate then you can just redo your calculations on the default ObjectPosition again. Basing it on the offset complicates matters & it will move from the current offset value to the new value - or at least it should.

    Imperator

    7152 Posts

  • #20, by ke4Wednesday, 22. March 2017, 14:50 5 years ago
    Ah right, the offset gets overwritten instead of making an offset from offset grin
    Thanks for making that clear.

    Key Killer

    810 Posts