What is vectorToAngle?

svnsvn Member Posts: 445
edited November -1 in Working with GS (Mac)
I use vectorToAngle for shooting, but I don't know how it works. Knowing could help me, since my game's shooting is going wonky. So what is vectorToAngle, and how does it work?

Comments

  • PhoticsPhotics Member Posts: 4,172
    svn said:
    I use vectorToAngle for shooting, but I don't know how it works. Knowing could help me, since my game's shooting is going wonky. So what is vectorToAngle, and how does it work?

    Basically, it can be used to compare two points and getting the angle between them.

    It starts out like this... vectorToAngle(x, y)

    For x... you can put the X locations for the two points...

    game.Mouse.Position.X - self.location.X

    Then the same can be done for the Y values...

    game.Mouse.Position.Y - self.location.Y

    The full formula could then be thrown in the "Angle" field of a "Rotate To Angle" behavior...

    vectorToAngle(game.Mouse.Position.X - self.location.X, game.Mouse.Position.Y - self.location.Y)

    The actor will then rotate to face the mouse.

    The Unofficial GameSalad Textbook has more information on this matter... like a chart to illustrate what's going on and examples of how vectorToAngle is useful.

    When vectorToAngle doesn't seem to be working properly for me, I check to see if I put the attributes in the right order... game.Mouse.Position.X - self.location.X is not the same as self.location.X - game.Mouse.Position.X.
  • svnsvn Member Posts: 445
    Thanks.
  • PhoticsPhotics Member Posts: 4,172
    svn said:
    Thanks.

    No problem!

    Also, depending on the scenario, the "Rotate To Position" behavior can be an alternative to vectorToAngle.
  • fzeedfzeed Member Posts: 247
    The book is pretty good, btw!
  • svnsvn Member Posts: 445
    Er, what book?
  • svnsvn Member Posts: 445
    I can't AFFORD the textbook!
  • PhoticsPhotics Member Posts: 4,172
    svn said:
    I can't AFFORD the textbook!

    The reply to your question wasn't enough information to solve the problem?
  • svnsvn Member Posts: 445
    Oh, it was! I was just commenting on fzeed and calvin9403's posts. But now there's one problem: the closer the actor gets to the mouse, the further back the bullets move, up to the point of moving in the opposite direction! What should I do?
  • LaurenSaladLaurenSalad Inactive, Chef Emeritus Posts: 650
    Hey svn,

    These are great question to ask on Cookbook. We're encouraging people to ask their "how tos" and "why does it do this" questions there. Thanks!
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    LaurenSalad said:
    Hey svn,

    These are great question to ask on Cookbook. We're encouraging people to ask their "how tos" and "why does it do this" questions there. Thanks!

    I do very much agree its a good question for the cookbook. But….. They didn't have access to that yesterday. ;)
  • svnsvn Member Posts: 445
    Okay, how do I move it to the Cookbook section? And by the way, can either of you help me? A Sous Chef or a Head Chef could surely help a Member.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    What do you need help with svn? Photics answered your question. You mean move to cookbook?
    Simple. You can't move it. LOL

    The cookbook is a whole different system than the forum. If you want to add the question you can go to the cookbook and scroll to the bottom and click add question. Then people will answer it. Although. The thing im not quite liking about the cookbook is we cannot seem to sort any of the questions. Say Maybe I want to go add Answers. I have to scroll through every single question and see if it has been answered. Really nee to have a new questions area and a way to sort by how many answers something has. IMO
Sign In or Register to comment.