Lua Corona SDK:如何使对象向前移动?
我有一个物理体,我希望它朝着它所面对的方向前进。我只有13岁,我希望这能解释为什么我在三角法方面如此糟糕。有人能告诉我在科罗纳怎么做吗。移动对象不需要三角函数 加 或者如果要执行转换Lua Corona SDK:如何使对象向前移动?,lua,coronasdk,Lua,Coronasdk,我有一个物理体,我希望它朝着它所面对的方向前进。我只有13岁,我希望这能解释为什么我在三角法方面如此糟糕。有人能告诉我在科罗纳怎么做吗。移动对象不需要三角函数 加 或者如果要执行转换 transition.to(object,{x=object.x + distanceToMoveInXAxis,y=object.y + distanceToMoveInYAxis}) 呃。移动对象不需要三角函数 加 或者如果要执行转换 transition.to(object,{x=object.x + di
transition.to(object,{x=object.x + distanceToMoveInXAxis,y=object.y + distanceToMoveInYAxis})
呃。移动对象不需要三角函数 加 或者如果要执行转换
transition.to(object,{x=object.x + distanceToMoveInXAxis,y=object.y + distanceToMoveInYAxis})
我假设你想用力推你的物体。无论哪种方法,我们都需要得到你身体所面对方向的x和y分量。以下是如何从旋转角度获取x和y:
-- body is your physics body
local angle = math.rad(body.rotation) -- we need angle in radians
local xComp = math.cos(angle) -- the x component
local yComp = -math.sin(angle) -- the y component is negative because
-- "up" the screen is negative
注意:如果这没有给出朝向,则可能需要将角度增加90度、180度或270度,例如:math.radbody.rotation+90
上面的代码将为您提供旋转方向的x和y分量。你可能还需要一些乘数来获得你想要的力的大小
local forceMag = 0.5 -- change this value to apply more or less force
-- now apply the force
body:applyLinearImpulse(forceMag*xComp, forceMag*yComp, body.x, body.y)
这是我得到数学知识的地方:。使用单位向量简化了数学,因为斜边总是1,我假设你想用一个力推动你的物体。无论哪种方法,我们都需要得到你身体所面对方向的x和y分量。以下是如何从旋转角度获取x和y:
-- body is your physics body
local angle = math.rad(body.rotation) -- we need angle in radians
local xComp = math.cos(angle) -- the x component
local yComp = -math.sin(angle) -- the y component is negative because
-- "up" the screen is negative
注意:如果这没有给出朝向,则可能需要将角度增加90度、180度或270度,例如:math.radbody.rotation+90
上面的代码将为您提供旋转方向的x和y分量。你可能还需要一些乘数来获得你想要的力的大小
local forceMag = 0.5 -- change this value to apply more or less force
-- now apply the force
body:applyLinearImpulse(forceMag*xComp, forceMag*yComp, body.x, body.y)
这是我得到数学知识的地方:。使用单位向量简化了数学,因为斜边总是1,在使用令人困惑的物理之前,让你自己的角色朝一个角度移动怎么样
angle = math.rad(Insert the angle you want here)
character.x = character.x - math.sin(angle)
character.y = character.y + math.cos(angle)
在使用令人困惑的物理之前,让你自己的角色朝一个角度移动怎么样
angle = math.rad(Insert the angle you want here)
character.x = character.x - math.sin(angle)
character.y = character.y + math.cos(angle)
查看最后一条评论,它可能是你要找的。查看最后一条评论,它可能是你要找的。他需要数学来计算从面对和速度/移动距离的X,Y移动平移。例如,如果他有一个200,56的物体,它的朝向是时钟上的一只指针的30°,我们想要移动62个像素,那么他对object:translate的论点是什么?他需要数学来计算从朝向和速度/移动距离的X,Y移动平移。例如,如果他有一个200,56的物体,它面对的是时钟上的一只指针30°,我们想要移动62个像素,那么他对物体的参数是什么:平移?