Pergunta

So I have a Java2D game when I have to rotate a cannon to the mouse's direction and save the angle. It works but I have the real issue. I can't calculate correct X and Y velocity from this answer i got from this equation:

double angle = Math.atan2(centerY - c.mouseY, centerX - c.mouseX) - Math.PI / 2;

then i use this equation:

int x = (int) Math.acos(c.rotation*Math.PI/180);
int y = (int) Math.sin(c.rotation*Math.PI/180);

I don't get the right velocity for y. can you guys help me?

Foi útil?

Solução

Maybe because your using cosine when calculating y value. Shouldn't it be sine?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top