Shooting bullet to another character [SOLVED]

  • #1, by TinTinSaturday, 14. January 2017, 09:17 3 years ago
    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 ?  

    Forum Fan

    193 Posts


  • #2, by ke4Saturday, 14. January 2017, 09:54 3 years ago
    You should be able to get the Y coordinate by this line of code

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

    You could then compare them like that

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

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

    IF char1.y == char2.y THEN
    1

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

    startAnimation(Animations["bullet"])
    1

    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)}
    1

    // 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)
    1

    And i'm not sure if this would actually work, i didn't test it, but hopefully it will give you an idea.

    Key Killer

    810 Posts

  • #3, by TinTinSaturday, 14. January 2017, 17:02 3 years ago
    Thanks a lot for reply

    I'll try it .

    Only a question : Does Bullet sprite move and collison with another character in your codes?

    Forum Fan

    193 Posts

  • #4, by ke4Saturday, 14. January 2017, 18:56 3 years ago
    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
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    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.

    Key Killer

    810 Posts

  • #5, by TinTinSunday, 15. January 2017, 16:29 3 years ago
    Ok. Thanks so much Ke4 . It works perfect .

    Forum Fan

    193 Posts

Write post