我正在尝试在love2D制作一个简单的平台游戏。目前我已将我的玩家类别放在其他东西中(碰撞处理类,等级等)
我遇到的主要问题是跳跃。我无法让它正常工作。
当我跳跃时,玩家被拉回太快,实际上使跳跃变得有用。为什么会这样?这是从ROBLOX移植的代码,在ROBLOX Studio中,跳转正常。
这是在玩家的更新功能中,每次从love.update:
调用if not love.keyboard.isDown("a") and not love.keyboard.isDown("d") then
self.Velocity=self.Velocity * Vector2.new(0.95,1)
end
if self.Velocity.Y < -self.maxFallVel then
self.Velocity=Vector2.new(self.Velocity.X,self.maxFallVel)
end
if love.keyboard.isDown("d") and self.Velocity.X<self.maxVel and not love.keyboard.isDown("a") then
self.Velocity = self.Velocity+Vector2.new(.1,0) -- right movement
end
if love.keyboard.isDown("a") and self.Velocity.X<self.maxVel and not love.keyboard.isDown("d") then
self.Velocity = self.Velocity-Vector2.new(.1,0) -- left movement
end
if love.keyboard.isDown("space") and self.hasCollision and not self.Jumped then
if self.Velocity.Y == 0 then
self.Velocity.Y = -30
end
end
self.Position=self.Position+Vector2.new(self.Velocity.X,self.Velocity.Y)
if not self.hasCollision then self.Velocity.Y = self.Velocity.Y - self.Gravity end
当我检查main.lua文件中的冲突时,我将变量self.hasCollision设置为true或false。
答案 0 :(得分:1)
if self.Velocity.Y < -self.maxFallVel then
self.Velocity=Vector2.new(self.Velocity.X, -self.maxFallVel) -- minus!
end
...
-- multiply by dt
self.Position=self.Position+Vector2.new(self.Velocity.X,self.Velocity.Y)*dt
if not self.hasCollision then
self.Velocity.Y = self.Velocity.Y - self.Gravity*dt
end