License from €75
DE EN FR ES IT CZ

How to determine the exact character position?

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 13 years ago
    Hi everyone,
    sorry in advance for my cheesy english. I would like to create a scene, in which the character gets hit (lets say by a punch or explosion) and therefore thumbles backwards and lands on the ground (shown in an animation). When he gets up again, his new position should be a couple feet away from where he was once standing. The problem is, that i dont know the exact character position, where he will be hit, it can be anywhere on the screen. So,
    1. How can i determine the exact character position at any given moment?
    2. How can i position my character in relation to his momentarily position (e.g. 50 pixels left on x-coordinate from where he is standing now)?

    Die Fragen nochmal in Deutsch:
    1. Wie kann ich die genaue Charakterposition zu jedem beliebigen Zeitpunkt bestimmen? Gibt es da irgendwelche Variablen, die man auslesen kann?
    2. Wie kann ich den Charakter in Relation zu seinem gegenwärtigen Standpunkt bewegen, z.B. 50 Pixel nach links auf der X-Achse?

    Thanks for any help.
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license. Forum readers get the Indie Bundle 15 % off with the code FORUM15: €84.15 instead of €99, valid until 31 Dec 2026.

    Get 15 % off Try it for free
  3. · 13 years ago
    hmm...
    -- examples of getting a character with Lua...
    game:getLink(VGameCurrentCharacter) -- get current character...
    getObject("Characters[character name here]") -- get linked character
    

    function: add script as a definition script...
    -- * local variables * --
    local char, pos
    
    -- * function for getting character position * --
    function setCharPos()
     char = game:getLink(VGameCurrentCharacter) -- get current character
     pos = char:getPoint(VCharacterPosition) -- stores character position into an x,y table
     -- * --
     char:setValue(VCharacterPosition, {x = pos.x - 50, y = pos.y)
     end
    

    usage: create an execute a script action and add:
    setCharPos()
    

    This is just a crude example.

    Just out of interest... wouldn't it be simpler to just change to an outfit where the character walk cycle contains the character laying down/sliding & just use that to move character to x destination?

    P.S: an issue I see with what you are wanting to do:
    * you have to take into consideration the characters current scale as the gap between point a & b would need to be less the further away the character is.
  4. · 13 years ago
    Thanks AFRLme,
    i will sure give it a try soon. Scaling is no issue for me, since the whole project is done in a side scroller perspective.
  5. · 9 years ago
    leider habe ichs auf diese weise nicht geschafft. ich möchte den charakter nach einer bestimmten animation lediglich um 5 pixel weiter nach links bzw. rechts rücken. auf diese weise klappt das leider nicht. 
  6. · 9 years ago
    in dem oben gezeigten Script scheint ne Klammer zu fehlen. Ich hab hier mal nen zweizeiler für ditsch:

    pos = game.CurrentCharacter.CharacterPosition
    game.CurrentCharacter.CharacterPosition = {x =pos.x - 5, y = pos.y} 
  7. · 9 years ago
    super! danke. kannst du mir noch sagen, wie ich statt "currentcharacter" einen bestimmten character anspreche? mit "game.Characters("katze").CharacterPosition" ging das nicht.
  8. · 9 years ago
    verschiedene Möglichkeiten :

    Characters["katze"]
    Characters.katze
    Characters[4]   - - wenn die katze die Position  4 in der Charakterliste hat
    getObject("Characters[katze]")  - - super veraltete Methode



    Am einfachsten kannst du dir die direkten" Links" zu den Objekten holen, wenn du in der Liste per Rechtsklick anklickst und dann "Luapfad kopieren" (oder so ähnlich) anwählst. Danach per strg+v in dein Script einfügen. 

  9. · 9 years ago
    Danke! Ich mach jetzt die ersten schritte mit lua. 
  10. · 9 years ago
    Danke! Ich mach jetzt die ersten schritte mit lua. 

    Ich persönlich finde die Schreibweise Characters["katze"] immer noch am besten, da du hier in den Eckigen klammern auch einen vorher dynamisch definierten Wert angeben kannst, welcher bei den anderen Methoden dann nicht möglich wäre:

    char = "katze"
    Characters[char]

    bei

    Characters.katze 

    geht das angeben einer variable verloren. wink



  11. · 9 years ago
    Danke! Ich mach jetzt die ersten schritte mit lua. 

    Ich persönlich finde die Schreibweise Characters["katze"] immer noch am besten, da du hier in den Eckigen klammern auch einen vorher dynamisch definierten Wert angeben kannst, welcher bei den anderen Methoden dann nicht möglich wäre:

    char = "katze"
    Characters[char]

    bei

    Characters.katze 

    geht das angeben einer variable verloren. wink



    +1 seconded. Using square brackets is best because you can input either the actual name wrapped in "name" or 'name' like so or you can input a variable or even link to another VisOBJ (visionaire object) in some cases such as an integer or string value stored inside of a variable or value that you created somewhere in the editor.

  12. · 9 years ago
    thank you! 

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?