I'm using built in physics engine for physics in my game, but I found out that there's either option to have no physical collision at all but detecting them (being a sensor), or having categories and groups support but no option to turn off physical collision (besides manually setting to each contact that it's disabled)
Is there a way to solve this problem? To be more concrete - I'm making a horizontal scroller shooter, and I need to prohibit collisions with enemies (because if I collide it feels funky) but I still need to detect collisions with them so I could apply damage to the player. And there are still some obstacles, so solution via making everything a sensor wouldn't work
Sensor but with collision
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Sensor but with collision
I would turn on sensors and then use categories to detect or ignore the events that are unimportant to you.
Last edited by togFox on Fri Jul 28, 2023 9:04 am, edited 2 times in total.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Re: Sensor but with collision
Use two rectangles in the same object: one for contact detection (larger) and one for collision solving (smaller).
Re: Sensor but with collision
I would recommend using love.physics that allows sensors. Sensors will still trigger onCollision callback, but won't affect physics, so you are all set.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Sensor but with collision
Sensors do not allow for any physical collisions, but they do call onCollision callbacks, I still need the option to make entities collide with walls
Re: Sensor but with collision
I've found the post with the same question, although there wasn't an answer there in the end viewtopic.php?p=241751
The only viable solution seems to be making something like my own category bits in userData of fixture and then checking then at collision and disabling it. But that seems strange that to get this simple behavior you need to manage it yourself. Is there no other solution?
The only viable solution seems to be making something like my own category bits in userData of fixture and then checking then at collision and disabling it. But that seems strange that to get this simple behavior you need to manage it yourself. Is there no other solution?
Re: Sensor but with collision
Yeah, so you can use sensors for enemies and normal colliders for walls.
Code for collisions is well explained here:
https://love2d.org/wiki/Tutorial:Physic ... nCallbacks
So you will need to create separate fixtures for your sensor-only colliders (*dynamic*, because enemies can move) and your physical types such as walls (those are *static* in addition).
Code: Select all
fixture:setSensor(true) -- for collider without physical effect that will still launch onCollision callback
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: Sensor but with collision
I guess I've badly explained this, but I still need, in such situation, enemies to physically collide with walls. If they are marked as sensors they would phase right through. I've marked my bullet entities as sensors and they just pass through any other entity even if it's a wall.dusoft wrote: ↑Sat Jul 29, 2023 8:50 amYeah, so you can use sensors for enemies and normal colliders for walls.
Code for collisions is well explained here:
https://love2d.org/wiki/Tutorial:Physic ... nCallbacks
So you will need to create separate fixtures for your sensor-only colliders (*dynamic*, because enemies can move) and your physical types such as walls (those are *static* in addition).
E.g. I am using sensors for detecting boat moved in space around a dock (rectangle, static, sensor) and normal fixture for a wooden dock/platform (rectangle, static, not a sensor). Boat can hit the dock and bump, but it can not hit the space around the dock that is just used for detection. Once boat is detected by the sensor (onCollision) and speed is zero, boat can board passengers on/off.Code: Select all
fixture:setSensor(true) -- for collider without physical effect that will still launch onCollision callback
So, to be more precise, in simplest situation, I need to have three entities - A, B, and W (wall), A and B collide with wall physically (bounce off, do not phase through it) and A and B need to be able to pass through each other with callbacks on, i.e. no collision but being able to detect if they are overlapping
Re: Sensor but with collision
Ah, I see. Maybe these functions could help? Setting same mask for both player and enemy wouldn't make them collide physically, but the onCollision callback should still work.Meevere wrote: ↑Sat Jul 29, 2023 4:04 pm So, to be more precise, in simplest situation, I need to have three entities - A, B, and W (wall), A and B collide with wall physically (bounce off, do not phase through it) and A and B need to be able to pass through each other with callbacks on, i.e. no collision but being able to detect if they are overlapping
https://love2d.org/wiki/Fixture:setMask
or
https://love2d.org/wiki/Fixture:setFilterData
Last edited by dusoft on Sun Jul 30, 2023 9:29 am, edited 1 time in total.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Who is online
Users browsing this forum: No registered users and 2 guests