Shooting bullet to another character [SOLVED]

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

    Fanoušek fóra

    196 Posts


  • #2, z ke4Saturday, 14. January 2017, 09:54 hodinky 8 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.

    Zabiják klíčů

    810 Posts

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

    Fanoušek fóra

    196 Posts

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

    Zabiják klíčů

    810 Posts

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

    Fanoušek fóra

    196 Posts