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

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

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?

pgimeno
Party member
Posts: 1180
Joined: Sun Oct 18, 2015 2:58 pm

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

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
The Microsoft Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

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

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

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?

pgimeno
Party member
Posts: 1180
Joined: Sun Oct 18, 2015 2:58 pm

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

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
The Microsoft Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

ivan
Party member
Posts: 1311
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

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

### Who is online

Users browsing this forum: Bing [Bot] and 15 guests