function lookto()
Posted: Fri Jul 18, 2008 2:15 am
a function for making actors look (or point) towards other actors or in certain directions
If anyone has used the usual (commonly used) formula for making an actor "turn towards" or "look towards" another actor or to "point" the actor in a certain direction, they may not have notice it has a flaw.
the formula I am talking about, is the one most often used in asteroids type games, to point the ship in a certain direction
eg: is commonly used for animations which are made up of rotated sprites, in order to select the correct frame in the correct direction
usually something like this......
The use of this code makes thing very easy, but has three major flaws..
1/ It is always a half frame off
2/ your animation frames must start at a certain frame and be rotated clockwise for it to work
(the first frame should point right)
3/some odd numbered animations simply will not line up correctly
(also there is another problem with smaller numbered frames (2, 3, 4,8) which I will explain in a later post)
So, I have written a function that compensates for the half frame problem, the odd numbered frame problem, and allows you to start on any frame of the animation (so doesn't matter which direction the starting frame is pointed) AND, IF, the spritesheet/animation is rotated anticlockwise it will compensate for that.
attached is a demo of the frame problem I am talking about.. most of the time you will not notice it, as most animations usually have 24,32, or 36 or more frames, making the few degrees each frame is off almost unnoticeable,
but if you are making a RPG, or have a four way top down game... you will quickly see the problem
notice carefully how the actors on the right turn before you finish leaving their field of view... whereas the "compensated actors" follow you correctly. This can easily be compensated for by the programmer once they notice it, with a simple addition/subtraction of angles, if your game is easy !..
later I will explain how hard that compensation issue can get in more complex games.
I will post the rest of the explanation soon ( the starting angles problem,the anticlockwise problem, etc) ...how to use... etc soon .
feral.
If anyone has used the usual (commonly used) formula for making an actor "turn towards" or "look towards" another actor or to "point" the actor in a certain direction, they may not have notice it has a flaw.
the formula I am talking about, is the one most often used in asteroids type games, to point the ship in a certain direction
eg: is commonly used for animations which are made up of rotated sprites, in order to select the correct frame in the correct direction
usually something like this......
- Code: Select all
ang=direction(x,y,player.x,player.y);
animpos=ang/360*nframes;
The use of this code makes thing very easy, but has three major flaws..
1/ It is always a half frame off
2/ your animation frames must start at a certain frame and be rotated clockwise for it to work
(the first frame should point right)
3/some odd numbered animations simply will not line up correctly
(also there is another problem with smaller numbered frames (2, 3, 4,8) which I will explain in a later post)
So, I have written a function that compensates for the half frame problem, the odd numbered frame problem, and allows you to start on any frame of the animation (so doesn't matter which direction the starting frame is pointed) AND, IF, the spritesheet/animation is rotated anticlockwise it will compensate for that.
attached is a demo of the frame problem I am talking about.. most of the time you will not notice it, as most animations usually have 24,32, or 36 or more frames, making the few degrees each frame is off almost unnoticeable,
but if you are making a RPG, or have a four way top down game... you will quickly see the problem
notice carefully how the actors on the right turn before you finish leaving their field of view... whereas the "compensated actors" follow you correctly. This can easily be compensated for by the programmer once they notice it, with a simple addition/subtraction of angles, if your game is easy !..
later I will explain how hard that compensation issue can get in more complex games.
I will post the rest of the explanation soon ( the starting angles problem,the anticlockwise problem, etc) ...how to use... etc soon .
feral.