I'd like to detect when two objects are approaching before the contact so evasive action is taken before a real contact event.
I could calculate distance between every object every second or so.
I also thought about making the body larger/wider than the image/graphic so the contact event fires before the images actually contact. I would then have to code my own 'real' contact event - which might be a lighter load on the processor.
Any other methods? Can I put two bodies of differing size centred on the same image? The first contact signals 'about to contact' and the second signal is a 'real contact'?
Box2D: detecting contact before contact
Box2D: detecting contact before contact
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Re: Box2D: detecting contact before contact
Looks liketogFox wrote: ↑Thu Aug 26, 2021 6:19 am I'd like to detect when two objects are approaching before the contact so evasive action is taken before a real contact event.
I could calculate distance between every object every second or so.
I also thought about making the body larger/wider than the image/graphic so the contact event fires before the images actually contact. I would then have to code my own 'real' contact event - which might be a lighter load on the processor.
Any other methods? Can I put two bodies of differing size centred on the same image? The first contact signals 'about to contact' and the second signal is a 'real contact'?
Code: Select all
function love.update(dt)
if is_contact (dt) then
do_contact (dt)
end
end
Or after the
v = v + dt*a
s = s + dt*v
check the collision and then back:
s = s - dt*v, you get the same situation as before, but you know that you can get the collision in this tick.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Box2D: detecting contact before contact
I haven't used box2d in awhile but you could indeed have two separate shapes and fixtures for one body. Mark one fixture as a sensor and it will not act on collisions. Look at the diagram in the link below to get a better idea.
https://love2d.org/wiki/love.physics
https://love2d.org/wiki/love.physics
Re: Box2D: detecting contact before contact
I'll try overlaying two shapes over the same image with the same origin and see how that goes. I've used Box2D on multiple Love projects so that seems the less intimidating to me. I'll call back on the other suggestions if necessary. Thanks all!
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 10 guests