how to apply LinearImpulse when object has velocity?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
OneOrigiN
Prole
Posts: 7
Joined: Fri Jul 24, 2020 3:04 pm

how to apply LinearImpulse when object has velocity?

Post by OneOrigiN »

So, when I'm applying linear impulse to object that moving because it has velocity - object (let's call him player) just start falling (looks like somebody turned physics on). But I want player to "jump" in some position (applyLinearImpulse()) when I want.

Here the code:

Code: Select all

function Player:jump(x, y)
  local x1, y1 = self.body:getLinearVelocity()
  self.body:applyLinearImpulse(x, y)
end

function Player:slide(x, y)
  self.body:setLinearVelocity(x, y)
end

function Player:update(dt)
  --print(self.is_mouse_released)
  --some code
  if (self.is_mouse_released == true) and (self.is_collisioned == true) then --self.is_collisioned is true only when player touchs something
    if self.is_sliding == true then
      self:jump(15*self.impulse_koff_x, 30*self.impulse_koff_y)
      self.is_sliding = false
    end
    self:jump(15*self.impulse_koff_x, 30*self.impulse_koff_y)
    self.is_mouse_released = false

  end
  if self.is_sliding == true then
     self:slide(0, 70)
  end

  if self.is_mouse_released == true then -- mouse is released only for 1 frame
    self.is_mouse_released = false
  end
end
-- mouse events

function Player:mouse_klicked()
  self.is_mouse_pressed = true
  self.is_mouse_released = false
end

function Player:mouse_released()
  --self:jump(15*self.impulse_koff_x, 30*self.impulse_koff_y)
  self.is_mouse_released = true
  self.is_mouse_pressed = false
end
P.S I hope I use events(mouse_clicked and so on) right?
Post Reply

Who is online

Users browsing this forum: targetcreature and 47 guests