Move object to absolute position with Lua.

  • #10, z ke4Friday, 04. December 2015, 08:58 hodinky 9 years ago
    Both :-)

    Zabiják klíčů

    810 Posts


  • #11, z MachtnixFriday, 04. December 2015, 23:42 hodinky 9 years ago
    Hi. I tried it and the position coordinates are not absolute, they are relative to the position the object has when the script starts. I copied your source code into a new script (executable) and called it by mouse click. But apart from that it works!

    Machtnix

    Kapitán

    1097 Posts

  • #12, z ke4Saturday, 05. December 2015, 10:10 hodinky 9 years ago
    It works for me, but math isn't my strong side though grin
    All that function does is receiving the current position of the object and then subtracts the position from the final position.

    Let's say you have an object at x980 y530
    You want to move it at x50 y50

    50 - 980 = -930
    50 - 530 = -480

    Or
    Let's say you have an object at x980 y530
    You want to move it at x1500 y700

    1500 - 980 = 520
    700 - 530 = 170

    Zabiják klíčů

    810 Posts

  • #13, z afrlmeSaturday, 05. December 2015, 11:59 hodinky 9 years ago
    I think the confusing part that people have trouble wrapping their heads around (myself included) is that you aren't moving the object & polygon itself to the new coordinates. It's actually moving the object interaction position you defined in the properties tab for the object (providing you set one) & everything else is offset accordingly from that point. It's more of a guessing game to be honest than anything else. If you know the exact difference between the top left pixel of your objects sprite / active animation & the objects position, then you'll probably have an easier time figuring out which coordinates you want to move it to.

    Imperátor

    7285 Posts

  • #14, z ke4Saturday, 05. December 2015, 12:13 hodinky 9 years ago
    Yeah it's not perfect, but i don't think it's that complicated either. All you need to do is to set your object interation position into the center of the object ( or anywhere else ) i guess it still needs to work with some positions even if you move through the action part, no?
    I have a minigame where you are throwing one thing and i needed to move the object to the position where i click it works with this.
    I think if there would be an option to specified the coordinates with values in the move object to action part then you could move the object through lua just by calling this action part and setting 2 values.

    Zabiják klíčů

    810 Posts

  • #15, z afrlmeSaturday, 05. December 2015, 12:24 hodinky 9 years ago
    The object position you define is supposed to be where the character will walk to before triggering the executed actions at destination actions. It's also used for auto aligning the character, the same goes for the align character to object action part.

    The only way I see setting the object position to the center of the object itself is ok is for menu scenes & objects that don't contain any execute command at destination actions for it.

    The mini-game you are talking about. Can you pick the object back up or interact with it again afterwards?

    Imperátor

    7285 Posts

  • #16, z ke4Saturday, 05. December 2015, 12:29 hodinky 9 years ago
    Yeah that's right... no i can't there is no interaction. So i guess it's pointless for classic objects.

    Zabiják klíčů

    810 Posts

  • #17, z afrlmeSaturday, 05. December 2015, 12:52 hodinky 9 years ago
    If you want to move something & it doesn't need to contain an object polygon, then it's probably easier & faster to create an animation & move that...
    ActiveAnimations["name"]:to(delay, { AnimationCurrentPosition = {x = 500, y = 500} }, easing)
    


    AnimationCurrentPosition is absolute. If you do need it to register the object on mouse over (display action text) then moving an object would be required instead.

    Imperátor

    7285 Posts

  • #18, z ke4Saturday, 05. December 2015, 14:47 hodinky 9 years ago
    Hmm why did i use object... Is it also possible to rotate that animation? I think it might been the reason.

    Zabiják klíčů

    810 Posts

  • #19, z afrlmeSaturday, 05. December 2015, 15:46 hodinky 9 years ago
    You can rotate the object. So I assume you can rotate an animation associated with the object. For a moving animation I think you would need a loop to constantly make sure the rotation center is in the center of the animation, so... animation position + x & y offset needed to get to center of animation. You could get the center by returning the size of the sprite & then dividing it in half for both height & width, but it would be slower to do that than manually defining the offset yourself.

    According to Simon we should now be able to directly draw images / text via Lua script. I'm not sure how yet, but I think we can control various parameters such as size, rotation, opacity & so on.

    Imperátor

    7285 Posts

  • #20, z MachtnixSunday, 06. December 2015, 03:50 hodinky 9 years ago
    I only want target coordinates the character could jump to. It doesn't matter if it's a absolute position or something else. If the player clicks on one of the field pipes I want to save
    1. the object the character is docking at (in my way it's only a zero object). that means one value (especially his name or ID)
    or
    2. the fixed position this object has. That means two values (x, y).

    Both cases are ok. But I didn't find a Vis procedure or a function which give me this coordinates by click. Maybe I have to create 25 action areas or I have to check the mouse position on every field to compare with the object below. I only want to put the values into a variable to exchange with another pipe modul from stack. Ke4's script is alright and well, but I haven't no position. So the mini game is blocked at the first step...

    Machtnix

    Kapitán

    1097 Posts