I am writing a game in which I am representing a velocity with a vector. I have a starting point and a point that I want the object to move towards at a certain speed. (I need the resulting vector's x and y values to add up to 800). I'm not sure what kind of formula I can use to accomplish this.
SO! I have a starting point. An "ending point". And need a vector whose x and y values add up to 800.
Here is the code I came up with:
dx = size.width / 2 - ball.position.x
dy = 800 - size.height / 2 - ball.position.y
ball.physicsBody?.velocity = CGVectorMake(dx, dy)
Although this appears to work, |dx| + |dy| != 800 and therefore the balls move at slightly different speeds. I'm sure I'm doing this wrong, but I'm not sure how to go about fixing it.