Rise / Run

Hello, I’m having troubles figuring out how to convert my direction (in degrees) to rise over run for my player’s x and y variables and still be able to limit the speed of the player.

Math.atan2 should do the job :slight_smile:

EDIT:
I’m lazy, and my reply suggests it aswell. I’m going to give you more than just that little hint: The source code I used to calculate the velocities of a projectile shot form the player.


Shot shot = new Shot(player.getX(), player.getY(),
			player.getRotation());
shot.setXV(shot.getXV()
			+ Math.cos(Math.toRadians(player.getRotation()))
			* GameMain.shotSpeed + player.getXVelocity());
shot.setYV(shot.getYV()
			+ Math.sin(Math.toRadians(player.getRotation()))
			* GameMain.shotSpeed + player.getYVelocity());

It should be pretty selfexplainatory. The angle was entered in radians, and is normally in degress for my convinience. :slight_smile:

Cheers! :slight_smile:

cos = X, sin = Y.

Yep, thanks a bunch guys, works perfectly!