0

私はコロナにまったく慣れていないので、身体を特定のポイントに移動する方法を知りたいですか?

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 に答える