Results 1 to 3 of 3

Thread: Game Question

  1. #1

    Thread Starter
    Lively Member jamieoboth's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    116

    Exclamation Game Question

    I need to know how to get a character to move (and face) in the directon that my mouse clicks, just like in settlers III and IV....

    Any examples?
    Ich widerstehe allem - nur nicht der Versuchung

    (I can resist anything but temptation)

  2. #2
    Zaei
    Guest
    First, you need to construct a facing vector. Take the point that the mouse clicked on, and subtract from it the position of the character:
    Code:
    Type vector
       x as Single
       y as Single
    End Type
      
    ...
    
    Dim mouseClick as vector
    Dim charPos as vector
    
    ...
    
    Dim facing as vector
    facing.x = mousePos.x - charPos.x
    facing.y = mousePos.y - charPos.y
    Now that you have a facing vector, you can use an arctangent to find the facing angle:
    Code:
    Dim faceAngle as Single
    
    faceAngle = atn(facing.y/facing.x)
    The above code will NOT give you the correct angle under certain circumstances (if facing.x is 0, if facing.x or facing.y is negative), but it should get you started.

    Z.

    [edit]
    faceAngle will also be in radians, with the code above. Multiply it by (180 / 3.14159) to get the actual angle in degrees.

  3. #3

    Thread Starter
    Lively Member jamieoboth's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    116
    Cool. Thanks Zaei!
    Ich widerstehe allem - nur nicht der Versuchung

    (I can resist anything but temptation)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width