ゲーム オブジェクトをタッチ位置に移動させようとしています。私はそれを行うためにさまざまな方法を試しましたが、すべて役に立ちませんでした。フレームごとにオブジェクトの y 位置を更新して、常に前進し続けるようにしていますが、これが力の追加に影響しているかどうかはわかりません。
カラスを移動する場所は次のとおりです (更新関数内)。
crow:translate((platformSpeed),0)
そして、カラスをタッチ位置に移動させようとしている場所は次のとおりです。
local function attack(xPos,yPos)
--get magnitude of touch vector
local magnitude = math.sqrt(xPos*2 + yPos*2)
--normalize vector
xPos = xPos / magnitude
yPos = yPos / magnitude
print(xPos..yPos)
local forceMag = 0.1 -- change this value to apply more or less force
--now apply the force
crow:setLinearVelocity(xPos*forceMag, yPos*forceMag)
--crow:applyLinearImpulse(xPos*forceMag, yPos*forceMag, crow.x, crow.y)
end
local function touchHandler(event)
if (event.phase == "began") then
end
if (event.phase == "ended") then
if (event.yStart>event.y+10) then
jump()
else attack(event.x,event.y) end
end
end
ご覧のとおり、私は線形速度と線形衝撃を試してきましたが、方向は常に間違っています!
どんな助けでも素晴らしいでしょう、ありがとう! アラン。