Move Object to Player position

  • #1, by lupoFriday, 14. June, 22:18 A month ago
    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

    8 Posts


  • #2, by esmeraldaSaturday, 15. June, 17:33 3 weeks ago
    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

    524 Posts

  • #3, by lupoSunday, 16. June, 18:13 3 weeks ago
    Like always, you are a master! Thanks a million!

    Newbie

    8 Posts

Write post