Bump how to ignore player?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Bump how to ignore player?

Post by hasen »

I noticed if I make my player run fast enough and his bullets slow enough he can crash into his own bullets and they get stuck to him. I thought I was supposed to use the :filter function to ignore that. I used the code from the Bump demo as follows but it doesn't ignore the player as parent of the bullet object. This is the code I have in the bullet object:

Code: Select all

function Bullet:filter(other)
  local kind = other.class.name
  if kind == 'Block'
  or kind == 'Enemy'
  or (kind == 'Player' and not self.ignoresParent)
  then
    return "slide"
  end
end
Should it be 'slide' or am I doing it all wrong?
User avatar
joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

Re: Bump how to ignore player?

Post by joedono »

"slide" is used if you want one object to NOT pass through another, but move along it. Like if you have a character run into a wall. If you want a bullet to pass through other objects, you'll want to use "cross" instead.

That said, if you want the bullet to completely ignore the player (like, a player shouldn't be able to shoot themselves), then you'd return nil instead of any of the other collision types.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Bump how to ignore player?

Post by hasen »

Ok you mean like this?

Code: Select all

  for i=1, len do
    local col = cols[1]
    local other = col.other
    local kind = other.class.name
    if kind == 'Enemy' or kind == 'Lava' then
      self:damageItem(other)
    elseif kind == 'Player' then
      return nil
    end
  end
This doesn't seem to work though.

I tried changing the filter to cross too but it didn't do anything. The bullets still get stopped by the player and either attach to him or end up being taken along with him.

Code: Select all

function Bullet:filter(other)
  local kind = other.class.name
  if kind == 'Block'
  or kind == 'Enemy'
  or (kind == 'Player' and not self.ignoresParent)
  then
    return "cross"
  end
end
Everything else seems to work fine. The bullets damage and kill the enemy etc. With returning 'cross' or nil the player still stops the bullet in its path.
User avatar
joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

Re: Bump how to ignore player?

Post by joedono »

You'll have to post the code that's using the filter then (whatever is calling Bump:move()). The problem is probably in there somewhere. Or your entire .love project if it suits you.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Bump how to ignore player?

Post by hasen »

It's ok I solved it...thanks.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 82 guests