0

我对 Corona 完全陌生,我想知道如何将身体移动到特定点?

4

1 回答 1

0

在这里,我推导出了将身体移动到特定点的公式

local force = 0.05    --Speed of body

local current_Position_X = myBody.x    --myBody is a physical body which has to move
local current_Position_Y = myBody.y

local N_Movement_X = target.x - current_Position_X    --target point where my body has to move
local N_Movement_Y = target.y - current_Position_Y

local N_Distance_X = N_Movement_X * N_Movement_X
local N_Distance_Y = N_Movement_Y * N_Movement_Y

local distance = math.sqrt(N_Distance_X + N_Distance_Y)
local unit = 1/distance

N_Movement_X = N_Distance_X * unit    --Normalizing distance
N_Movement_Y = N_Distance_Y * unit    --Normalizing distance

local forceX = distance * N_Movement_X
local forceY = distance * N_Movement_Y

myBody:setLinearVelocity(forceX*force, forceY* force)
于 2013-06-14T04:28:25.760 回答