Shooting bullet to another character [SOLVED]

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

    196 Posts


  • #2, by ke4Saturday, 14. January 2017, 09:54 7 years ago
    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.

    Key Killer

    810 Posts

  • #3, by TinTinSaturday, 14. January 2017, 17:02 7 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

    196 Posts

  • #4, by ke4Saturday, 14. January 2017, 18:56 7 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

    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 7 years ago
    Ok. Thanks so much Ke4 . It works perfect .

    Forum Fan

    196 Posts