Contact:getNormal's y-coordinate is 0, vector also is not unit

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
TheHUG
Prole
Posts: 9
Joined: Sun Apr 01, 2018 4:21 pm

Contact:getNormal's y-coordinate is 0, vector also is not unit

Post by TheHUG » Wed Jul 11, 2018 9:51 am

Hi, I decided I might like a little more control over the collisions in my game, so I set all the colliding objects to sensors (I realize that at this point HardonCollider might be better to use than the love2d physics package, but I wanted to try this out without refactoring everything else first).

I then planned to manage physical behavior on collision by getting the relevant information from the contact object passed through beginContact.

It probably doesn´t matter, but I am using windfield (for its nifty packaging the fixtures/bodies/shapes into one, I don't like its version of collision detection, so maybe I'll eventually write something that only does the former)
I wasn´t getting the behavior I expected, and when I checked it turned out that contact:getNormal was giving (7.19..., 0) , which is neither correct, nor a unit vector.

Code: Select all

function collide_bounce(obja, objb, coll)
   local fa, fb = coll:getFixtures()
   print(obja.fixture, fa)
   print(objb.fixture, fb)
   
   local nx, ny = coll:getNormal()
   print(nx, ny)
   ...
end
which is called by the collision callback beginContact:

Code: Select all

function beginContact(a, b, coll)
   local obja = a:getUserData()
   local objb = b:getUserData()
   ...
         local i = collide_bounce(obja, objb, coll)
 end
This happens repeatedly, at various impact angles.
In this case the two Colliders are circles.

Also, potentially unrelated: after the circles pass through each other, they register a variety of collisions when they are not touching.

Any ideas what could be going on?

User avatar
pgimeno
Party member
Posts: 1332
Joined: Sun Oct 18, 2015 2:58 pm

Re: Contact:getNormal's y-coordinate is 0, vector also is not unit

Post by pgimeno » Wed Jul 11, 2018 1:48 pm

TheHUG wrote:
Wed Jul 11, 2018 9:51 am
I set all the colliding objects to sensors
Sensors don't generate normals. No idea what getNormal is returning in such case, though. Probably garbage.

https://stackoverflow.com/questions/971 ... box2d-2-1a

TheHUG wrote:
Wed Jul 11, 2018 9:51 am
Also, potentially unrelated: after the circles pass through each other, they register a variety of collisions when they are not touching.
I remember having seen that if you go through the list of contacts, you get a contact when the axis-aligned bounding boxes collide, and you need Contact:isTouching to determine whether they're actually touching.

http://www.iforce2d.net/b2dtut/collision-anatomy

Is that what you mean?
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

TheHUG
Prole
Posts: 9
Joined: Sun Apr 01, 2018 4:21 pm

Re: Contact:getNormal's y-coordinate is 0, vector also is not unit

Post by TheHUG » Sun Jul 29, 2018 11:24 am

Thanks! sorry I posted and vanished, I hadn't had time to think about this for a while, life's been hectic. It explains for the normals, thanks. I'm not sure about the aligned boxes, what callbacks are called when the axis-aligned boxes intersect, but not the rest?

User avatar
pgimeno
Party member
Posts: 1332
Joined: Sun Oct 18, 2015 2:58 pm

Re: Contact:getNormal's y-coordinate is 0, vector also is not unit

Post by pgimeno » Sun Jul 29, 2018 3:29 pm

In theory you don't get a callback, but if you're checking the list of contacts regularly, you get a contact. That's why I asked if that's what you meant.

Can you provide a test case that shows the problem?
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

User avatar
ivan
Party member
Posts: 1341
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Contact:getNormal's y-coordinate is 0, vector also is not unit

Post by ivan » Sun Jul 29, 2018 4:25 pm

Yes, Pgimeno is correct.
Furthermore, you don't want to use sensors in this case.
In "beginContact" you can call contact:setEnabled(false).

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests