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

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], molul and 2 guests