lua - Y Velocity is inconsistent moving between 8 and something else? -


i added entity framework code (sorta half done) , after added noticed wrong y velocity of player seems fluctuate between 1 , 0. stumped why has occurred assume it's current physics i've put in not sure happening. code below:

collisions.lua

-- btw not code needed aabb work right  function iscolliding(a,b)       if ((b.x >= a.x + a.width) or          (b.x + b.width <= a.x) or          (b.y >= a.y + a.height) or          (b.y + b.height <= a.y))            return false        else return true            end    end  -- 'a' must entity can move  -- 'b' can static object -- both need height, width, x , y value function ifcolliding(a, b)      if iscolliding(a,b)          if a.y + a.height < b.y              a.y = b.y - a.height             a.yvel = 0         elseif a.y - a.height > b.y - b.height             a.y = b.y + b.height             a.yvel = 0         end      end   end 

entitybase.lua

local entitybase = {}  lg = love.graphics      -- set health     entitybase.health = 100      -- set acceleration     entitybase.accel = 3000      -- set y velocity     entitybase.yvel = 0.0      -- set x velocity     entitybase.xvel = 0.0      -- set y position     entitybase.y = 0      -- set x position     entitybase.x = 0      -- set height     entitybase.height = 64      -- set width      entitybase.width = 64      -- set friction     entitybase.friction = 0      -- set jump     entitybase.jump = 350      -- set mass     entitybase.mass = 50       -- set detection radius     entitybase.radius = 100      -- sets boolean value if player can jump     entitybase.canjump = true      -- sets image default     entitybase.img = nil  ------------------------------------------------ -- physics ensure movement works -- ------------------------------------------------  function entitybase.physics(dt)       -- sets x position of entities     entitybase.x = entitybase.x + entitybase.xvel * dt      -- sets y position of entities     entitybase.y = entitybase.y + entitybase.yvel * dt      -- sets y velocity  of entities     entitybase.yvel = entitybase.yvel + (gravity  * entitybase.mass) * dt      -- sets x velocity of entities     entitybase.xvel = entitybase.xvel * (1 - math.min(dt * entitybase.friction, 1))  end  -- entity jump feature function entitybase:dojump()      -- if entities y velocity = 0 subtract yvel jump value     if entitybase.yvel == 0         entitybase.yvel = entitybase.yvel - entitybase.jump     end  end  -- updates jump function entitybase:jumpupdate(dt)      if entitybase.yvel ~= 0         entitybase.y = entitybase.y + entitybase.yvel * dt          entitybase.yvel = entitybase.yvel - gravity * dt     end  end  function entitybase:update(dt)      entitybase:jumpupdate(dt)     entitybase.physics(dt)     entitybase.move(dt)  end  return entitybase 

sorry chucking in didn't know needed show don't know whats creating problem, have had , looks collisions maybe, not sure. anyway thank want have crack @ problem if needs explaining or understanding i'll try best clear up.

fix timestep , don't use dt physics calcualtions.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -