Menu
Login
Language
DE EN FR ES IT CZ
Back

Move Object to Player position

  • #1, by lupo Friday, 14. June 2024, 22:18 A year ago Quote
    How to set an objects position to the players characters position? I would like to have the character to drop an object where he is positioned. The user should see the object on the correct position then as a graphic. Any idea? 

    Newbie

    13 Posts

  • #2, by esmeralda Saturday, 15. June 2024, 17:33 A year ago Quote
    I can't think of a way without scripting.

    Add the object to your scene, but leave it positioned at 0,0. Link a condition to it and hide it by setting the condition to false (or true, depending on how you set your conditons).

    In the action that should drop the item add an "execute script" action part with this line:
    Objects["obj_name"].Offset = game.CurrentCharacter.Position
    Then change the condition, so the object is active.

    (instead of obj_name use the name of your object - the one in the list of scene objects)
    This sets the object to the position of the character, i.e. its animation center. Position of the object is defined by the upper left corner of the object image.

    Objects don't have a Position field we can access with scripting, we need to use the Offset field and to make that work properly, the objects needs to be at the (0,0) position, else the offset will be added to the position of the object.
    If the position is not quite right for you, you can either move the object from the (0,0) position or change the line of script. For example:
    Objects["obj_name"].Offset = {x = game.CurrentCharacter.Position.x - 20, y = game.CurrentCharacter.Position.y + 10}

    The numbers are in pixel.

    Key Killer

    567 Posts

  • #3, by lupo Sunday, 16. June 2024, 18:13 A year ago Quote
    Like always, you are a master! Thanks a million!

    Newbie

    13 Posts