how to detect if a collider is tuching a nothere collider in the physics system in love2d

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
A-lox
Prole
Posts: 43
Joined: Sun Apr 10, 2022 1:58 am

how to detect if a collider is tuching a nothere collider in the physics system in love2d

Post by A-lox »

I need help
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: how to detect if a collider is tuching a nothere collider in the physics system in love2d

Post by Andlac028 »

Try to look at Body:isTouching or World:getContacts if you use love.physics.
A-lox
Prole
Posts: 43
Joined: Sun Apr 10, 2022 1:58 am

Re: how to detect if a collider is tuching a nothere collider in the physics system in love2d

Post by A-lox »

Andlac028 wrote: Sat Feb 18, 2023 5:50 am Try to look at Body:isTouching or World:getContacts if you use love. physics.
when I use enemy.hitbox:isTuching(player.hitbox)
then it gives me this error:

Error: main.lua:193: bad argument #1 to 'isTouching' (Body expected, got table)
stack traceback:
[love "boot.lua"]:345: in function <[love "boot.lua"]:341>
[C]: in function 'isTouching'
main.lua:193: in function 'enemy_del'
main.lua:50: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: how to detect if a collider is tuching a nothere collider in the physics system in love2d

Post by Andlac028 »

A-lox wrote: Sat Feb 18, 2023 2:44 pm
Andlac028 wrote: Sat Feb 18, 2023 5:50 am Try to look at Body:isTouching or World:getContacts if you use love. physics.
when I use enemy.hitbox:isTuching(player.hitbox)
then it gives me this error:

Error: main.lua:193: bad argument #1 to 'isTouching' (Body expected, got table)
stack traceback:
[love "boot.lua"]:345: in function <[love "boot.lua"]:341>
[C]: in function 'isTouching'
main.lua:193: in function 'enemy_del'
main.lua:50: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
I don’t know, what player.hitbox is, but you should pass body as argument, not table. Just find, where you save player body during creation of player (love.physics.newBody()) and use it as argument instread of player.hitbox.

If you need help with this please share your code or some reproducible example (or if it is problem to post it publically, PM it to me so I can help you (I will delete the copy of it after problem is solved))
Last edited by Andlac028 on Sat Feb 18, 2023 3:52 pm, edited 1 time in total.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: how to detect if a collider is tuching a nothere collider in the physics system in love2d

Post by Bigfoot71 »

A-lox wrote: Sat Feb 18, 2023 2:44 pm
Andlac028 wrote: Sat Feb 18, 2023 5:50 am Try to look at Body:isTouching or World:getContacts if you use love. physics.
when I use enemy.hitbox:isTuching(player.hitbox)
then it gives me this error:

Error: main.lua:193: bad argument #1 to 'isTouching' (Body expected, got table)
stack traceback:
[love "boot.lua"]:345: in function <[love "boot.lua"]:341>
[C]: in function 'isTouching'
main.lua:193: in function 'enemy_del'
main.lua:50: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
It simply means that the value you give as parameter of :isTouching is not a Body "object" but a table.
What does the "hitbox" value represent? Do you use a physics library such as windfield or other?

Share your code with us, it will be easier to help you ^^
My avatar code for the curious :D V1, V2, V3.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests