When i first decided i wanted to program games, i thought all this talk about mathematics begin needed to be a pile of rubbish. O how foolish i was.
I was soon to discover that to make a camera move in the direction your facing isn’t exactly y+=1. It requires quite a large amount of trigonometry and general mathematical knowledge. Although, it does feel really good when you finally manage to work out algorithms by your self, over the weekend i managed to make a missile fly towards the player facing in the direction it is travelling
For those of you interested here is the maths:
For the movement:
directionX = targetX - positionX
directionY = targetY - positionY
hypotenuse = √((directionX^2)+(directionY^2))
directionX = directionX / hypotenuse
directionY = directionY / hypotenuse
For the rotation:
rotation = tan-1((positionX-targetX)/(positionY-targetY))
So yeah, i know it seems pretty newbie but i was quite proud i was able to work that all out by myself. Anyway gotta keep this post short because i’ve gotta go right now!