Moving an object at different angles...

I want to move a ball at different angles, but the farther away from 45?I get, the faster the ball moves (because the x or y value is so much larger than the other). I am adding deltaX and deltaY to my posX and posY variables. How can I make it so that the ball travels at the same speed no matter what angle it is going? Thanks.

[336 byte] By [Ak586a] at [2007-9-29 12:23:59]
# 1
try searching the forums.
Abusea at 2007-7-15 2:14:57 > top of Java-index,Other Topics,Java Game Development...
# 2

Trigonometry. sin and cosin.

Think of velocity being represented by a length, and the possible directions for a given velocity forming a circle (working in 2D here) around the object in question, with the radius being the velocity.

Then you can use basic trig to find the x and y components of a given velocity in a given direction.

paulcwa at 2007-7-15 2:14:57 > top of Java-index,Other Topics,Java Game Development...
# 3
dx = Math.cos(angle)*velocity;dy = Math.sin(angle)*velocity;x += dx;y += dy;woo :)
Malohkana at 2007-7-15 2:14:57 > top of Java-index,Other Topics,Java Game Development...