Hi, I'm still exploring the possibilities of solving the problem stated in this topic: viewtopic.php?f=3&t=5066&start=0
I want to have a player body that collects and reacts to contacts collected from the world bodies, but itself does not change their movement. Like the mass difference between those bodies was infinite - big bodies being dynamic when interacting with one another, but static when interacting with player body. I want to process player contacts myself, solve them simply by manipulating player position and if they are unsolvable report that the player has been squished.
My current approach goes like this:
-disable contacts concerning player body via contact listener
-collect them by GetContactList()
Then, for each contact:
-get the normal vector from contact manifold
-get the distance between the center of players body and the other shape
-if the distance is lower than player's body radius, move the body according to normal vector.
(what do you think of this approach? If you can point me to a better solution I would be thankful. It seems a bit hacky to me :/)
I used the distance test from the C++ TestBed as a base. To get distance between player's body center and other body, I have a dummy b2CircleShape, that has radius = 0 and transform copied from PlayerOuter body (BTW, is there a simpler way of doing that? Without the dummy shape.).
(in code below X is a b2ContactEdge extracted by PlayerOuter.GetContactList())
This reports a null object reference for b2Distance.Distance(distOut, cache, distIn).
It either is a bug, or I am doing something wrong. Any suggestions?
I want to have a player body that collects and reacts to contacts collected from the world bodies, but itself does not change their movement. Like the mass difference between those bodies was infinite - big bodies being dynamic when interacting with one another, but static when interacting with player body. I want to process player contacts myself, solve them simply by manipulating player position and if they are unsolvable report that the player has been squished.
My current approach goes like this:
-disable contacts concerning player body via contact listener
-collect them by GetContactList()
Then, for each contact:
-get the normal vector from contact manifold
-get the distance between the center of players body and the other shape
-if the distance is lower than player's body radius, move the body according to normal vector.
(what do you think of this approach? If you can point me to a better solution I would be thankful. It seems a bit hacky to me :/)
I used the distance test from the C++ TestBed as a base. To get distance between player's body center and other body, I have a dummy b2CircleShape, that has radius = 0 and transform copied from PlayerOuter body (BTW, is there a simpler way of doing that? Without the dummy shape.).
(in code below X is a b2ContactEdge extracted by PlayerOuter.GetContactList())
Code:
var distIn: b2DistanceInput = new b2DistanceInput();
distIn.transformA = X.contact.GetFixtureA().GetBody().m_xf;
distIn.transformB = PlayerOuter.m_xf;
var proxyA: b2DistanceProxy = new b2DistanceProxy();
proxyA.Set(X.contact.GetFixtureA().GetShape());
var proxyB: b2DistanceProxy = new b2DistanceProxy();
proxyB.Set(X.contact.GetFixtureB().GetShape());
distIn.useRadii = true;
var distOut: b2DistanceOutput;
var cache: b2SimplexCache = new b2SimplexCache();
cache.count = 0;
b2Distance.Distance(distOut, cache, distIn);
trace(distOut.distance);
distIn.transformA = X.contact.GetFixtureA().GetBody().m_xf;
distIn.transformB = PlayerOuter.m_xf;
var proxyA: b2DistanceProxy = new b2DistanceProxy();
proxyA.Set(X.contact.GetFixtureA().GetShape());
var proxyB: b2DistanceProxy = new b2DistanceProxy();
proxyB.Set(X.contact.GetFixtureB().GetShape());
distIn.useRadii = true;
var distOut: b2DistanceOutput;
var cache: b2SimplexCache = new b2SimplexCache();
cache.count = 0;
b2Distance.Distance(distOut, cache, distIn);
trace(distOut.distance);
This reports a null object reference for b2Distance.Distance(distOut, cache, distIn).
Code:
at b2Simplex/ReadCache()[D:\Praca\Programowanie\Flash\Projekty\ProtoBox\src\Box2D\Collision\b2Simplex.as:80]
at Box2D.Collision::b2Distance$/Distance()[D:\Praca\Programowanie\Flash\Projekty\ProtoBox\src\Box2D\Collision\b2Distance.as:56]
at Box2D.Collision::b2Distance$/Distance()[D:\Praca\Programowanie\Flash\Projekty\ProtoBox\src\Box2D\Collision\b2Distance.as:56]
It either is a bug, or I am doing something wrong. Any suggestions?