fix(part): hinge joint only made if other part intersects the hinge
This commit is contained in:
parent
dcc1f64354
commit
df6e2ac98d
3 changed files with 7 additions and 5 deletions
|
@ -28,7 +28,7 @@ void Rotate::buildJoint() {
|
|||
part1.lock()->cframe = newFrame;
|
||||
workspace->SyncPartPhysics(part1.lock());
|
||||
// Do NOT use Abs() in this scenario. For some reason that breaks it
|
||||
rp::HingeJointInfo jointInfo(part0.lock()->rigidBody, part1.lock()->rigidBody, newFrame.Position(), -(part0.lock()->cframe * c0).LookVector().Unit());
|
||||
rp::HingeJointInfo jointInfo(part0.lock()->rigidBody, part1.lock()->rigidBody, (part0.lock()->cframe * c0).Position(), -(part0.lock()->cframe * c0).LookVector().Unit());
|
||||
this->joint = dynamic_cast<rp::HingeJoint*>(workspace->physicsWorld->createJoint(jointInfo));
|
||||
jointWorkspace = workspace;
|
||||
|
||||
|
|
|
@ -183,8 +183,7 @@ bool Part::checkJointContinuityUp(std::shared_ptr<Part> otherPart) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Part::checkSurfacesTouching(CFrame surfaceFrame, Vector3 myFace, Vector3 otherFace, std::shared_ptr<Part> otherPart) {
|
||||
// Vector3 otherPartCenterToMine = surfaceFrame.Inverse() * otherPart->cframe.Position();
|
||||
bool Part::checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3 myFace, Vector3 otherFace, std::shared_ptr<Part> otherPart) {
|
||||
Vector3 farCorner0 = surfaceFrame.Inverse() * otherPart->cframe * (Vector3::ONE * (otherPart->size / 2.f));
|
||||
Vector3 farCorner1 = surfaceFrame.Inverse() * otherPart->cframe * (-Vector3::ONE * (otherPart->size / 2.f));
|
||||
|
||||
|
@ -251,12 +250,15 @@ void Part::MakeJoints() {
|
|||
if (dot > -0.99) continue; // Surface is pointing opposite to ours
|
||||
|
||||
if (abs(surfacePointLocalToMyFrame.Z()) > 0.05) continue; // Surfaces are within 0.05 studs of one another
|
||||
if (!checkSurfacesTouching(surfaceFrame, myFace, otherFace, otherPart)) continue; // Surface do not overlap
|
||||
if (!checkSurfacesTouching(surfaceFrame, size, myFace, otherFace, otherPart)) continue; // Surface do not overlap
|
||||
if (!checkJointContinuity(otherPart)) continue;
|
||||
|
||||
SurfaceType mySurface = surfaceFromFace(faceFromNormal(myFace));
|
||||
SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace));
|
||||
|
||||
// If it is a hinge, only attach if actually touching the "hinge"
|
||||
if (mySurface == SurfaceHinge && !checkSurfacesTouching(surfaceFrame, Vector3(0.4, 0.4, 0.4), myFace, otherFace, otherPart)) continue;
|
||||
|
||||
// Create contacts
|
||||
// Contact always occurs at the center of Part0's surface (even if that point does not overlap both surfaces)
|
||||
// Contact 0 is Part0's contact relative to Part0. It should point *opposite* the direction of its surface normal
|
||||
|
|
|
@ -43,7 +43,7 @@ protected:
|
|||
bool checkJointContinuity(std::shared_ptr<Part>);
|
||||
bool checkJointContinuityUp(std::shared_ptr<Part>);
|
||||
bool checkJointContinuityDown(std::shared_ptr<Part>);
|
||||
bool checkSurfacesTouching(CFrame surfaceFrame, Vector3 myFace, Vector3 otherFace, std::shared_ptr<Part> otherPart);
|
||||
bool checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3 myFace, Vector3 otherFace, std::shared_ptr<Part> otherPart);
|
||||
|
||||
friend JointInstance;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue