これは純粋な物理的な質問ですが、なぜうまくいかないのかわかりません....私は動いている物体を持っています.私はvcos(シータ)とvsin(シータ)の値を取得します...これから計算します動きの速度と角度.....また、別のポイント(x、y)を知っていて、オブジェクトをこのポイントに向けたいと思います。特定の力(力にはX軸とY軸の値が必要です)を適用する必要があると思いますオブジェクトをポイントに向けます....必要な力の量を取得するには、次の式に従います。
fX=V2cos(θ2)-V1cos(θ1) fY=V2sin(θ2)-V1sin(θ1)
シンテックスが以下に与えられたものに関係なく(私はそれらの人々が目的cを知っているためにそれを与えます........私の方程式は機能しません....誰か助けてくれますか...
if (acceleration.x>1.5 || acceleration.y>1.5) {
shakeCounter++;
[_label setString:[NSString stringWithFormat:@"%d",shakeCounter]];
//get the velocity of moving object.......................
b2Vec2 mVelik = ballBody->GetLinearVelocityFromLocalPoint(localPoint);
float angleOfCurrentDirectionOfMotion;
float angleOfDesiredDirectionOfMotion;
//calculate first velocity
float V1=sqrt(pow(mVelik.x, 2)+pow(mVelik.y, 2));
//calculate second velocity
float V2=V1+factor;
//calculate current angle
angleOfCurrentDirectionOfMotion=atan(mVelik.y/mVelik.x);
//calculate desired angle
angleOfDesiredDirectionOfMotion=atan(acceleration.y/acceleration.x);
///calculate FX and FY
float X=V2*cos(angleOfDesiredDirectionOfMotion)-V1*cos(angleOfCurrentDirectionOfMotion);
float Y=V2*sin(angleOfDesiredDirectionOfMotion)-V1*sin(angleOfCurrentDirectionOfMotion);
b2Vec2 force = b2Vec2(X,Y);
///apply Force to change direction....
ballBody->ApplyForce(force, ballBody->GetPosition());
}