Original Post
Hi all I'm trying to overcome my lack of maths by building simple 2d Game Engine,
But I've run into a small problem i want the game engine to allow you to set speed either based on direction and speed or by just using xspeed and yspeed. I've done this by calculating the x and y speeds whenever the speed or direction of an object changes like so:
But even though my Engine only uses the x and y speeds to update the objects position I still need to update the speed and direction in case a games code uses it in there code otherwise it would cause logic errors/unexpected results I calculate the speed as follows:
But I'm clueless as how to calculate the Direction.Thanks to anyone who can help. And Sorry If its to noobish a question.
But I've run into a small problem i want the game engine to allow you to set speed either based on direction and speed or by just using xspeed and yspeed. I've done this by calculating the x and y speeds whenever the speed or direction of an object changes like so:
xspeed = cosine(Direction) * speed
yspeed = sine(Direction) * speed
But even though my Engine only uses the x and y speeds to update the objects position I still need to update the speed and direction in case a games code uses it in there code otherwise it would cause logic errors/unexpected results I calculate the speed as follows:
speed = sqaureroot(xspeed^2 + yspeed^2)
But I'm clueless as how to calculate the Direction.Thanks to anyone who can help. And Sorry If its to noobish a question.