I have two problems. I'll start with the easiest. I have a normal FPS with a player that accelerates when you press w and deaccelerates when you let go. Simple except the player 'drifts' after you release the key.
This is the code I'm using to deaccelerate:
if(my.relx > 0.2)
// where my.relx is the relative movement value in the x direction
{
my.relx -= 0.5;
}
if(my.relx < -0.2)
{
my.relx += 0.5;
}
you would expect the player to atleast drift backwards, but this is not so, it continues to drift forwards. I have tried adapting all the values but it doesn't see to have any affect, whats more this 'drift' seems to happen randomly, sometimes it stops as needed, others it keeps going slowly in the same dirrection with a value of a round 0.15, positive.
Also my other problem is a turning one. In my game I have oppponents that, if they sense you, will spin to face you. Originally I simply set the enemies 'pan' value to the dirrection needed to face the player but this is jerky and unnatural so i used a piece of code that finds the difference between the dirrection the entity should be facing and the current pan values, it then rotated the entity by this value so that as it get close to its mark is slows down forming a more natural action, however dispite trying this only lets the entity rotate one way and even worse sometimes it does multiple spins before reaching its target.
Any suggestions ot these problems?
Thanks!