2017-01-25 7 views
1

私はlove2Dでシンプルなプラットフォーマーを作ろうとしています。現在、私は他のものの中で自分のプレーヤークラスを持っています(衝突処理クラス、レベルクラスなど)重力と衝突でジャンプする

私が持っている主な問題はジャンプです。私はちょうどそれが適切に動作するようにすることはできません。

私がジャンプすると、プレイヤーは実際にジャンプを有効にするにはあまりにも速く戻ってきます。なぜこうなった?これはROBLOXから移植されたコードであり、ROBLOX Studioではジャンプが正常に機能します。私は、変数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からのすべてのフレームと呼ばれるプレイヤーの更新関数の内部にあります正しいか間違っているか。

答えて

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 
関連する問題