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

Shooting bullet to another character [SOLVED]

  • #1, by TinTin 9 years ago Zitieren
    Hi

    I have a little battle into the game.How can I shoot a bullet sprite in straight way to another character and character die when two character are in equal y coordinate ?  
  • #2, by ke4 9 years ago Zitieren
    You should be able to get the Y coordinate by this line of code

    char1 = Characters["name1"].CharacterPosition
    char2 = Characters["name2"].CharacterPosition

    You could then compare them like that

    IF char2.y >= (char1.y-10) AND char2.y <= (char1.y+10) THEN

    To be in a range of 10, or if you want it to be exact

    IF char1.y == char2.y THEN

    For the bullet i suppose you could use animation, first you would start the animation

    startAnimation(Animations["bullet"])

    Then you would set the position for the animation based on where the character currently is

    ActiveAnimations["bullet"].CurrentPosition = { x = char1.x, y = (char1.y-X)}

    // You would need to calc the number of pixels you want to offeset the bullet for the X
    And you could then animate the bullet with the To function

    ActiveAnimations["bullet"]:to(200, { CurrentPosition = { x = char2.x, y = (char1.y-X)} }, easeQuintOut)

    And i'm not sure if this would actually work, i didn't test it, but hopefully it will give you an idea.
  • #3, by TinTin 9 years ago Zitieren
    Thanks a lot for reply

    I'll try it .

    Only a question : Does Bullet sprite move and collison with another character in your codes?
  • #4, by ke4 9 years ago Zitieren
    No there's no collision.

    char1 = Characters["name1"].CharacterPosition
    
    char2 = Characters["name2"].CharacterPosition
    
    startAnimation(Animations["bullet"])
    ActiveAnimations["bullet"].CurrentPosition = { x = char1.x, y = (char1.y-X)}
    ActiveAnimations["bullet"]:to(200, { CurrentPosition = { x = char2.x, y = (char1.y-X)} }, easeQuintOut)
    
    WAIT FOR 200 ms
    
    
    IF char2.y >= (char1.y-10) AND char2.y <= (char1.y+10) THEN
    
        --collison code / anything you want
    
    ENDIF

    I suppose you could just wait for these 200 ms or the time wou would set for the bullet movement. The bullet is being moved to the X position of the second character, so when it's on the place it should be the "collision".
    This is of course just a really simple solution. It depends on what you are really trying to achieve there. You will need to be creative though as there are no collisions built directly in Visionaire.
  • #5, by TinTin 9 years ago Zitieren
    Ok. Thanks so much Ke4 . It works perfect .