Move object to a position using a value

  • #1, by constantinWednesday, 27. September 2017, 13:20 7 years ago
    Hallo,
    entschuldigt, aber ich habe keine Antwort auf diese Frage gefunden.
    Ist der action part "move object to" nur eingeschränkt benutzbar? Ich versuche, ein Objekt auf eine bestimmte Position zu setzen. Diese ist aber jedes Mal verschieden und wird durch Variablen definiert. 
    Wie kann ich ein Objekt auf die Position "x" und "y" verschieben? 
    Danke
    Constantin

    Hello,
    I'm sorry, but I couldn't find an answer to that question.
    Is the action part "move object to" limited? I'm trying to move an object to a specific position. However, this position is always different and is defined by variables.
    How can I move an object to the positions "x" and "y"? 
    Thanks
    Constantin

    Forum Fan

    167 Posts


  • #2, by SimonSWednesday, 27. September 2017, 14:51 7 years ago
    Move object to ist aktuell auf vordefinierte Positionen beschränkt. Wenn du Values nutzen willst, dann per Lua:

    Objects["name"].Offset = { x=Value["xwert"].Int, y=Value["ywert"].Int }

    Thread Captain

    1580 Posts

  • #3, by afrlmeWednesday, 27. September 2017, 15:04 7 years ago
    Quick note: moving an object with Lua script using the offset field will offset from wherever the default position is that you set for the object. The only way without using math calculations to set an absolute position is to have the object position & image set to 0,0 on the x & y axis by default, which isn't ideal in most situations.

    Imperator

    7278 Posts

  • #4, by constantinWednesday, 27. September 2017, 18:31 7 years ago
    danke - ich hab das versucht, aber irgendwie klappt das nicht. das objekt bewegt sich nicht. wahrscheinlich verstehe ich etwas grundlegendes bei der verwendung von lua nicht. 

    Forum Fan

    167 Posts

  • #5, by afrlmeWednesday, 27. September 2017, 20:25 7 years ago
    Objects is global & if you have multiple objects with the same name then it will likely confuse the engine. Names are also case sensitive.

    Based on Simon's code example, let's say you have a scene object called "ball" & that you have 2 values one called "ball_x" & the other called "ball_y", so to offset the ball to the value positions you need to create an exectute a script somewhere & then add something along the lines of this...
    game.CurrentScene.SceneObjects["ball"]:to(1000, { ObjectOffset = {x = Values["ball_y"].Int, y = Values["ball_y"].Int} }) -- move ball to offset values specified in the 2 values over 1000ms (1 second)

    Now this is all fine, but the issue here is the ObjectPosition field is not scriptable & only the ObjectOffset field is scriptable, but it's actually an offset value & not absolute position, which means that the offset values in the values are incorrect because it will be offsetting x,y pixels from the current position of the scene object. To correct this you need to do some math to determine whether the new value is greater than, less than or the same as the object position & then you need to calculate the distance between the 2 points to get the actual offset value for absolute positioning. It's a pain in the arse. If you just want to move an image around the screen then I recommend using an animation instead as those can be positioned absolutely.

    Imperator

    7278 Posts

  • #6, by constantinFriday, 29. September 2017, 17:35 7 years ago
    Danke. Ich sehe, dass du eines der hilfreichsten mitglieder im forum bist. Danke natürlich auch allen anderen. Ich finde es großartig, wie man sich hier gegenseitig weiterhilft.  

    Forum Fan

    167 Posts

  • #7, by MachtnixFriday, 29. September 2017, 17:44 7 years ago
    Falls Lua zu umständlich ist, generiere ich einfach ein unsichtbares Dummy-Objekt, plaziere es auf der Kulisse und lasse den Charakter mit der Aktion „gehe zu Objekt“ dahinlaufen. Wenn man es nicht benennt, poppt auch kein Infotext auf; der Mauszeiger verrät es dennoch. 

    Thread Captain

    1097 Posts