License from €75
DE EN FR ES IT CZ

how to compare position between mc and other characters?

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

  1. · 8 years ago
    Since I'm trying to make a basic beat em up system, I'd need a way to compare mc and opponent position so that if mc is punching and y x cordinate beetween him and an opponent are between a determined range the punch triggers a pain animation to the opponent. How can I achieve this with a script?
  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.

    See licenses Try it for free
  3. · 8 years ago
    definition script
    function compareCharDist(atk, def)
    
     if Characters[atk].Position.x < Characters[def].Position.x and (Characters[def].Position.x - Characters[atk].Position.x) <= 100 then
    
     -- hit (attacker is on left)
    
    elseif if Characters[atk].Position.x > Characters[def].Position.x and (Characters[atk].Position.x - Characters[def].Position.x) <= 100 then
    
     -- hit (attacker is on right)
    
     end
    
    end

    usage: (execute a script)
    compareCharDist("Tom", "Harry")
  4. · 8 years ago
    I've been trying that setDelay example to see if I could detect when a character is in range and it seems to work well BUT I'm really not sure if its a good idea to have it running for an extended period of time also the range depends on how fast the delay runs.
    a delay of 250ms is enough if you check for a a character 50px away..

  5. · 8 years ago
    Thank you I am gonna try it
  6. · 8 years ago
    I've been trying that setDelay example to see if I could detect when a character is in range and it seems to work well BUT I'm really not sure if its a good idea to have it running for an extended period of time also the range depends on how fast the delay runs.
    a delay of 250ms is enough if you check for a a character 50px away..

    Hence check directly via the relevant animation frame. Why bother with delays, when you can sync much easier by checking on the relevant animation frames?

  7. · 8 years ago
    Sorry for the naive question, but where do I write the definition script? Does it not go in "exectute script" right?
  8. · 8 years ago
    In the script section of the editor. create a new script. by default it will be a definition type script.

    There are 2 script types...
    1. Definition: scripts of this type will be executed on game load - useful for declaring variables & functions.
    2. Execution: scripts of this type will be executed when called - useful for small/simple single use scripts.
  9. · 8 years ago
    In the script section of the editor. create a new script. by default it will be a definition type script.

    There are 2 script types...
    1. Definition: scripts of this type will be executed on game load - useful for declaring variables & functions.
    2. Execution: scripts of this type will be executed when called - useful for small/simple single use scripts.

    Quick note: the script I pasted was an example. It won't do anything unless you edit it & tell it what it's supposed to do. Such as play hurt animation of the opponent... maybe something along the lines of this...
    startAnimation(Characters[def].CurrentOutfit.CharacterAnimations["hurt"])
  10. · 8 years ago
    function compareCharDist(MC,opponent)
    
    NearOpponentStandingRight =  getObject("Conditions[NearOpponentStandingRight]")
    NearOpponentStandingLeft =  getObject("Conditions[NearOpponentStandingLeft]")
    
    
     if Characters[MC].Position.x < Characters[opponent].Position.x and (Characters[opponent].Position.x - Characters[MC].Position.x) <= 100 then
    
    
    setCondition("nearEnough", true)
    NearOpponentStandingLeft:setValue(VConditionValue, true)
    NearOpponentStandingRight:setValue(VConditionValue, false)
    -- hit (attacker is on left)
    
    elseif
    
    
    Characters[MC].Position.x > Characters[opponent].Position.x and (Characters[MC].Position.x - Characters[opponent].Position.x) <= 100 then
    
    
    setCondition("nearEnough", true)
    NearOpponentStandingRight:setValue(VConditionValue, true)
    NearOpponentStandingLeft:setValue(VConditionValue, false)
    
     
    -- hit (attacker is on right)
     end
    end
    
    
    
    
    compareCharDist("MC", "opponent")

    I was wondering if it's ok, I added two variables that switch once the distance is in range.
    I added the execute script to a keyboard input to run it and check if the variable switch but it doesn't work. I also substitute the character names of the function, do they need quotation marks?

    edit: ignore "setCondition("nearEnough", true)" which I paste/copied by error
  11. · 8 years ago
    function distanceScriptTry (mc, opponent)
    
    standingRight =  getObject("Conditions[standingRight]") 
    standingLeft =  getObject("Conditions[standingLeft]")
    mc = getObject("Characters[MC]")
    opponent = getObject("Characters[opponent]")
    
    
    
    if mc.Position.x + opponent.Position.x >=1 
    
    and
    
    mc.Position.x + opponent.Position.x <=300
    
    then
    
    standingRight:setValue(VConditionValue, true)
    
    else
    
    standingRight:setValue(VConditionValue, false)
    
    end
    
    if mc.Position.x - opponent.Position.x <=-1 
    
    and
    
    
    mc.Position.x - opponent.Position.x >=-300
    
    then
    
    standingLeft:setValue(VConditionValue, true)
    
    else
    
    standingLeft:setValue(VConditionValue, false)
    
    end
    end
    
    
    I also made this scritp which works for the left side, the standingLeft variable works and switches when distance is on range, but the standingRight variable doesn't work
  12. · 8 years ago
    This works:

    function distanceScriptTry (mc, opponent)
    
    standingRight =  getObject("Conditions[standingRight]") 
    standingLeft =  getObject("Conditions[standingLeft]")
    mc = getObject("Characters[MC]")
    opponent = getObject("Characters[opponent]")
    
    
    if mc.Position.x < opponent.Position.x
    
    and
    
    mc.Position.x - opponent.Position.x >=-300
    
    then
    
    standingLeft:setValue(VConditionValue, true)
    
    else
    
    standingLeft:setValue(VConditionValue, false)
    
    end
    
    if mc.Position.x > opponent.Position.x 
    
    and
    
    mc.Position.x - opponent.Position.x <=300
    
    then
    
    standingRight:setValue(VConditionValue, true)
    
    else
    
    standingRight:setValue(VConditionValue, false)
    
    end
    end
    
    

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?