2d collision with rotated pictures

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.
razerbladex43
Prole
Posts: 5
Joined: Mon Oct 26, 2020 12:08 am

2d collision with rotated pictures

Post by razerbladex43 »

Hi everyone,
i have a big question. my problem is that i want make a collision system beetwen two rotated/angled sprites. theses sprites are both same sizes and they have rectangle form. I need it for the tank game i'm actually making and it's very urgent so i need your help.
thanks in advance.
User avatar
FloatingBanana
Prole
Posts: 22
Joined: Sat Mar 02, 2019 4:57 pm
Contact:

Re: 2d collision with rotated pictures

Post by FloatingBanana »

Take a look at the HC library.

Code: Select all

if anyMistake(self.english) then
    print("Sorry, english is not my first language")
end
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: 2d collision with rotated pictures

Post by ivan »

Rotated rectangles are not simple and it's even harder if you want to have some sort of decent collision response.
I recommend using love.physics or avoid rotation altogether.
For example, you can use circles or just rotate the sprite without rotating the collision mask.
dezoitodemaio
Prole
Posts: 15
Joined: Mon Oct 26, 2020 2:02 pm

Re: 2d collision with rotated pictures

Post by dezoitodemaio »

Since rectangles are made of lines you could check line to line collision, something like https://github.com/processing/processin ... -Detection. If any line of Rectangle A intersects any line of Rectangle B then there are colliding.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: 2d collision with rotated pictures

Post by ivan »

dezoitodemaio wrote: Mon Oct 26, 2020 2:06 pm Since rectangles are made of lines you could check line to line collision
Additionally one rectangle could be entirely inside another.
User avatar
nikneym
Citizen
Posts: 56
Joined: Sat Mar 09, 2013 1:22 pm
Contact:

Re: 2d collision with rotated pictures

Post by nikneym »

razerbladex43 wrote: Mon Oct 26, 2020 12:13 am Hi everyone,
i have a big question. my problem is that i want make a collision system beetwen two rotated/angled sprites. theses sprites are both same sizes and they have rectangle form. I need it for the tank game i'm actually making and it's very urgent so i need your help.
thanks in advance.
SAT collision detection may solve your problem. There is a tutorial of SAT implementation made by recursor but this might mean you have to change your collision detection script completely.
razerbladex43
Prole
Posts: 5
Joined: Mon Oct 26, 2020 12:08 am

Re: 2d collision with rotated pictures

Post by razerbladex43 »

I'm actualling trying to understand the separating axis theorem but it seems to difficult. also i know hc but i prefer sat i think i'll try to understand. do you know a french tutorial for the sat because i'm not familiar with english language
razerbladex43
Prole
Posts: 5
Joined: Mon Oct 26, 2020 12:08 am

Re: 2d collision with rotated pictures

Post by razerbladex43 »

dezoitodemaio wrote: Mon Oct 26, 2020 2:06 pm Since rectangles are made of lines you could check line to line collision, something like https://github.com/processing/processin ... -Detection. If any line of Rectangle A intersects any line of Rectangle B then there are colliding.
i'll try to implement this also
razerbladex43
Prole
Posts: 5
Joined: Mon Oct 26, 2020 12:08 am

Re: 2d collision with rotated pictures

Post by razerbladex43 »

the game i'm making is very similar to this one https://awesometanks2.com/ and if you can give it a look and tell me what kind of collision system they are using that would be very nice
User avatar
siberian
Prole
Posts: 23
Joined: Sat Apr 06, 2019 1:42 pm

Re: 2d collision with rotated pictures

Post by siberian »

May be will be usefull.
The main idea is to get the sum of the 2 shapes (hull). If the center of an object is inside a hull, the objects are intersecting.
In motion, check the intersection of the hull with a segment from the center of the moved object to its destination point.

Image
The attachment rotated_boxes.love is no longer available
Attachments
rotated_boxes.love
intersection and collision of rotating boxes
(3.76 KiB) Downloaded 288 times
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests