禁用某些物理的重力

时间:2017-08-02 12:56:00

标签: lua love2d

如何使用LOVE物理学为Lua禁用某些物理的重力?

blocks.ground.body = love.physics.newBody(world, 0, blocks.ground.y, "dynamic")
blocks.ground.shape = love.physics.newRectangleShape(500, 50)
blocks.ground.fixture = love.physics.newFixture(blocks.ground.body, blocks.ground.shape)
blocks.ground.color = {86,176,0}

这是我目前的身体代码,我还需要它保持“动态”,因为我需要移动它的X

查看完整代码: code

1 个答案:

答案 0 :(得分:0)

假设您使用LÖVE0.8.0+:

选项1:

您的代码:

blocks.ground.body = love.physics.newBody(world, 0, blocks.ground.y, "dynamic")
blocks.ground.shape = love.physics.newRectangleShape(500, 50)
blocks.ground.fixture = love.physics.newFixture(blocks.ground.body, blocks.ground.shape)
blocks.ground.color = {86,176,0}

注意:在您的代码love.physics.newFixture(blocks.ground.body, blocks.ground.shape)

来自LOVE的网站(1):

objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape) --attach shape to body

也来自LOVE的网站(2):

objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1) -- Attach fixture to body and give it a density of 1.

在他们网站的第二个片段中,他们将球密度(质量)设置为1。同样,您应该能够将质量设置为0,在这种情况下,重力对对象没有影响。但是,如果其他物体与物体0碰撞,我不确定可能会出现什么类型的时髦行为。

选项2:

另一种选择是创建一个重力为0的新世界:

love.physics.setMeter(64) --the height of a meter our worlds will be 64px
  worldNoGravity = love.physics.newWorld(0, 0, true) 

然后将身体添加到该世界:

blocks.ground.body = love.physics.newBody(worldNoGravity , 0, blocks.ground.y, "dynamic")
blocks.ground.shape = love.physics.newRectangleShape(500, 50)
blocks.ground.fixture = love.physics.newFixture(blocks.ground.body, blocks.ground.shape)
blocks.ground.color = {86,176,0}

希望其中一个能为你效劳:)。