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
Citizen
Posts: 61
Joined: Sun Apr 01, 2018 4:21 pm

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

Post by TheHUG »

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: 3544
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

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

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

Post by TheHUG »

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: 3544
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

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?
User avatar
ivan
Party member
Posts: 1911
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 »

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: Bing [Bot], Google [Bot] and 43 guests