1
나는 love2D에서 간단한 platformer를 만들려고합니다. 현재 다른 플레이어들 (충돌 처리 클래스, 레벨 클래스 등) 중에서 플레이어 클래스를 가지고 있습니다.중력 및 충돌로 점프
주요 문제는 점프입니다. 나는 제대로 작동하지 못합니다.
내가 점프 할 때, 플레이어는 실제로 점프를 유용하게 만들기에는 너무 빨리 뒤로 당겨집니다. 왜 이런 일이 일어나는 걸까요? 이것은 ROBLOX에서 포팅 된 코드이며 ROBLOX Studio에서는 점프가 정상적으로 작동합니다. I가 변수 self.hasCollision를 설정 곳
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 파일 내의 충돌을 확인, 그건 :
이 love.update에서 매 프레임마다 호출되는 플레이어의 업데이트 기능 내부 true 또는 false.