Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

how to compare position between mc and other characters?

  • #1, by nerd 7 years ago Zitieren
    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, by afrlme 7 years ago Zitieren
    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")
  • #3, by Nigec 7 years ago Zitieren
    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..

  • #4, by nerd 7 years ago Zitieren
    Thank you I am gonna try it
  • #5, by afrlme 7 years ago Zitieren
    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?

  • #6, by nerd 7 years ago Zitieren
    Sorry for the naive question, but where do I write the definition script? Does it not go in "exectute script" right?
  • #7, by afrlme 7 years ago Zitieren
    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.
  • #8, by afrlme 7 years ago Zitieren
    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"])
  • #9, by nerd 7 years ago Zitieren
    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
  • #10, by nerd 7 years ago Zitieren
    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
  • #11, by nerd 7 years ago Zitieren
    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