How would i detect collison between a player and object using box2d

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
l0ki77
Prole
Posts: 6
Joined: Tue Apr 18, 2023 7:55 pm

How would i detect collison between a player and object using box2d

Post by l0ki77 »

Hello I am currently making a game for my class and I was wondering how I would detect Collison between a Player and object using box2d. I would also wondering how you could spawn the object that the player collided with in a random location on the tiled map through the lenses of a camera.
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: How would i detect collison between a player and object using box2d

Post by darkfrei »

l0ki77 wrote: Sat Apr 29, 2023 1:29 am Hello I am currently making a game for my class and I was wondering how I would detect Collison between a Player and object using box2d. I would also wondering how you could spawn the object that the player collided with in a random location on the tiled map through the lenses of a camera.
Just from documentation:

Code: Select all

  if playerFixture:isTouching(objectFixture) then
https://love2d.org/wiki/Body:isTouching

or
https://love2d.org/wiki/World:queryBoundingBox
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How would i detect collison between a player and object using box2d

Post by dusoft »

Use contacts: https://love2d.org/wiki/Contact
Specifically create callbacks:
https://love2d.org/wiki/World:setCallbacks

I *would not* recommend using functions mentioned above as the documentation states they are not recommended and might miss collisions.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 4 guests