【发布时间】:2017-06-10 07:44:20
【问题描述】:
我正在尝试在 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。
【问题讨论】: