我对Corona来说是全新的,我想知道如何将身体移动到特定的位置?
答案 0 :(得分: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)