Page 1 of 1

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

Posted: Sat Feb 18, 2023 2:47 am
by A-lox
I need help

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

Posted: Sat Feb 18, 2023 5:50 am
by Andlac028
Try to look at Body:isTouching or World:getContacts if you use love.physics.

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

Posted: Sat Feb 18, 2023 2:44 pm
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'

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

Posted: Sat Feb 18, 2023 3:48 pm
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))

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

Posted: Sat Feb 18, 2023 3:52 pm
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 ^^