Getting the player Character to face mouse direction

Started by Aljoho, Wed 23/04/2008 11:58:14

Previous topic - Next topic

Aljoho

   I've been trying for a while now to make a script to make the character face the mouse loacation, using an 8 way character. Ive done the incredibly easy part but of course this means that he will always face up and down, unless you are on the exact y location of the player, this is also useless for an 8 way character, how can i get it to work with relatively straight lines, or at least so that within certain blocks of say 50 by 50 the player can face so it is a square edged triangle for the mouse to go in, however little that makes sense :o
   So far this is just the simple bit I have:

    if (mouse.x > player.x) player.FaceLocation(cCharacter.x + 50,cCharacter.y);
    if (mouse.x < player.x) player.FaceLocation(cCharacter.x - 50,cCharacter.y);
    if (mouse.y > player.y) player.FaceLocation(cCharacter.x,cCharacter.y + 50);
    if (mouse.y < player.y) player.FaceLocation(cCharacter.x,cCharacter.y - 50);

   If anyone can understand my bad explanation help would be greatly appreciated
A Tribute to my success -  A wonky ASCII Trophy
                              .__.
                              (|  |)
                               (  )
                              _)(_

Khris

player.FaceLocation(mouse.x+GetViewPortX(), mouse.y+GetViewPortY());

(You don't even need the viewport stuff if there aren't any scrolling rooms in your game.)

Aljoho

wow that simple cant believe i didnt think of that

cheers a bunch
;D
A Tribute to my success -  A wonky ASCII Trophy
                              .__.
                              (|  |)
                               (  )
                              _)(_

Aljoho

   Having said that use direction 4-7 is set to true for my player but he still doesnt face the diagonal directions? ???
A Tribute to my success -  A wonky ASCII Trophy
                              .__.
                              (|  |)
                               (  )
                              _)(_

Khris

For testing purposes, comment out the line of code, then put "player.FaceLocation(player.x+5, player.y+5);" in after fadein.
Does the character switch to the diagonal loop? (i.e. does facing diagonally work at all?)

Aljoho

A Tribute to my success -  A wonky ASCII Trophy
                              .__.
                              (|  |)
                               (  )
                              _)(_

Khris

Then my guess is that the player's NormalView isn't set up correctly.

SMF spam blocked by CleanTalk