Positioning Shots Problem (asked by svn)

svnsvn Member Posts: 445
edited November -1 in Working with GS (Mac)
I'm making a shooter game. The shots are supposed to move to the mouse's position, but the necessary rules mean that when your character moves, and the mouse is on him, the shots stay where in the character. How can I tell it to move in a linear fashion, but it moves in a hypothetical invisible line stretching from the character to the mouse and beyond?(Sorry if this gets confusing, just play any web shooter game, like the excellent Commando 2[miniclip.com/games/commando-2/en/] , and watch how the shots move to see what I mean)

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    use vector to angle to determine the angle of the shot from the player to the mouse position, then you can use magnitude to determine how close the mouse is to the player and if its within the range you want have it so the shots dont move and stay where the character is

    vector to angle expression: vectorToAngle(selfposition.x-mousepositon.x,self.position.y-mouse.position.y)

    magnitude expression: magnitude(self.position.x-mouse.position.x,self.position.y-mouse.position.y)

    tsb has a great video called distance between actors in the gamesalad cookbook that shows magnitude as well
  • svnsvn Member Posts: 445
    No, no. You're misinterpreting my query(my fault entirelly). What I want is for the bullet to shoot in a straight line, passing through the mouse's position. Should I interpolate the move behaviors to the mouse position or something? Play any 2D web shooter game to see what I mean.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    ahh i see. All you need to do then is have a change velocity behavior in the bullet and for the direction have vectorToAngle(self.position.x-mouse.posiiton.x,self.posiiton.y-mouse.position.y)

    that will have it shoot towards the mouse and keep going past it in the same direction, so it doesnt just go to the mouse and stop
  • svnsvn Member Posts: 445
    Thanks, John. You're a big help, man.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    anytime
  • svnsvn Member Posts: 445
    Hey! What happened?! I followed JohnPapiomitis' instructions, but the bullet moves in the opposite direction and angle. What is going on?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    thats weird, it should be workign right

    you can do: -vectorToAngle(self.position.x-mouse.posiiton.x,self.posiiton.y-mouse.position.y)

    since its going the opposite having the minus will make it the right way, thats still puzziling why its not working from the get go though
  • svnsvn Member Posts: 445
    Hey, what if.. For the "self.position.x/y- mouse.position.x/y" ,.is the self.position for the bullet itself, or the actor it should fire from? And is the mouse.position.x mean "game.mouse.position.x"?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    no the expressions right

    and i just remeber, the image of the player should be facing right to begin with, if its facing left thats why its shooting out the other side. Im refereing to the actual png you imported into gamesalad
  • svnsvn Member Posts: 445
    John, I just found out what went wrong! Turns out, the equation is actually "VectortoAngle(GAME.MOUSE.POSITION.X/Y- SELF.POSITION.X/Y). You wrote the numbers in the wrong order, but that was it!
Sign In or Register to comment.