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?:confused: :confused: :confused:
Printable View
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?:confused: :confused: :confused:
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:
Now that you have a facing vector, you can use an arctangent to find the facing angle: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
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.Code:Dim faceAngle as Single
faceAngle = atn(facing.y/facing.x)
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.
Cool. Thanks Zaei!