我想使對象滑過鼠標,每次它被點擊。它會不斷移動。現在,如果我點擊它的前面(上方或下方),它會朝大體方向移動,但角度不對。當我點擊後面時,它會減慢很多,最接近它的速度非常緩慢。如何使對象「飛」到鼠標XNA
if (isdown()) //if the mouse is clicked
{
double paulx = Paullocation.X + radius; //midpoints of object
double pauly = Paullocation.Y + radius;
double targetx = ms.X; //clicked location
double targety = ms.Y;
if (isdown(Keys.Space)) //if space is pressed
{
double hypotenuse = Math.Sqrt(Math.Pow(paulx - targetx, 2) + Math.Pow(pauly - targety, 2));
//finds hypotenuse^
double xcomponent = targetx - paulx; //finds both legs of triangle
double ycomponent = targety - pauly; //that is made by mouse
Paulincrement.X = (float)Math.Cos(xcomponent/hypotenuse); //main issue
Paulincrement.Y = (float)Math.Sin(ycomponent/hypotenuse); //main issue
}
}
Paullocation.X += Paulincrement.X;
Paullocation.Y += Paulincrement.Y;
你爲什麼使用cos/sin?他們在這方面對我來說沒有意義。 – lukegravitt
我需要找到從鼠標創建的假想三角形的角度和對象的位置,找出多少「x」和多少「y」來添加。 – user2939446