Help with "facing" routine
- Posted by Einar Mogen <nord.staernes at ROLLAG.MAIL.TELIA.COM> Jul 01, 1998
- 701 views
I would like some help on a function that should work like this: I pass it two sequences, the first one containing the coordinates of the active character, the second one containg the coordinates of the point that the active character should look at. I have a total of 24 facings, the first one being directly up, the second 15 degrees to the right, the second 30 degrees to the right, and so on. They are indexed 1-24. The function is supposed to return the facing index that most closely matches the character looking towards the point. If anyone out there which is more stable at mathematics like this could help me with the routine (it should be as fast as possible, since it will be called many times each frame of the game) then I would be very grateful. I've started working on it, but now I'm both lazy and tired, and I'm not too keen on this kind of mathematics. Following is an outline of the function: function determine_facing(sequence char_pos, sequence point) -- find the closest match of the 24 possibilites return facing -- 1 to 24 end function Any help is greatly appreciated, the main thing I'm out for is the fastest way to find the angle which the point is at, relative to the character, either in degrees (or radians) or even better expressed with the indexes. Einar (who hopes his english is not _totally_ hopeless)