Surface normals vs x/y normals

Benk10

  • Posts: 21
In physics, a surface normal is simply a vector that is perpendicular to the surface.
Stencyl includes "x-normal" and "y-normal" blocks under Collision -> Collision Points, which need to be used with the "For Each collision point" loop.
However, I doubt these are surface normals. Have a look here: http://www.iforce2d.net/b2dtut/collision-anatomy
This seems to say that these normals in box2D are not surface normals but are rather vectors indicating where and in which direction impulse should be applied to most efficiently  separate objects in contact. This may not necessarily be a surface normal.
So if the x/y normals in Stencyl are the same as these box2D normals, they are NOT surface normals!

So then, how do I find out the surface normal? I need to know this to implement beam refraction.

Alexin

  • *
  • Posts: 3127
I think your assumption is correct. However I have used the normal reported by Stencyl many times in the past and it was never different than the surface normal I expected.

The engine is hosted on Github, so you can confirm the source code and, if necessary, build a custom version for your use case.

To get you started:
com.stencyl.models.Actor.handleCollisions()
box2D.collision.B2WorldManifold.getPoint()
"Find the fun"
alexin@stencyl.com

Benk10

  • Posts: 21
Thanks.

arctan2(y-normal / x-normal) of Last Collided Actor as degrees

appears to give a surface normal, at least for the case of a round object colliding with a flat surface.
I now have working outside-to-in refraction. Now i need inside-to-out refraction. Can an object collide with the internal of another object's bounding box?

Benk10

  • Posts: 21
Hmm. There is a big problem with implementing refraction from inside to outside.
First, the photon must pass through the prism. We can use the workaround of changing the photon's animation to one without a bounding box, but then we must know when to change it back.
Worse, it must be changed back in order to collide with the inner boundary. However, if it gets changed back while the photon is still inside the prism, the prism attempts to eject it.

You might think that making the prism into a sensor would solve this problem, but it doesn't. If the prism is made into a sensor, then the photons can pass through but the x and y normals do not work correctly. In other words, sensors aren't simply physics-less collisions. Some of the collision functionality does not work at all with sensors, such as detecting which side of an actor was hit. This really makes no sense, and I have a thread in the Suggestions sub-forum about this.