diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 2c9df287b..2167d2aa6 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -2735,7 +2735,7 @@ namespace wiScene { SceneIntersectSphereResult result; XMVECTOR vCenter = XMLoadFloat3(&sphere.center); - XMVECTOR vRadius = XMVectorReplicatePtr(&sphere.radius); + XMVECTOR vRadius = XMVectorReplicate(sphere.radius); XMVECTOR RadiusSq = XMVectorMultiply(vRadius, vRadius); if (scene.objects.GetCount() > 0) @@ -2822,10 +2822,10 @@ namespace wiScene // Find the nearest feature on the triangle to the sphere. XMVECTOR Dist = XMVector3Dot(XMVectorSubtract(vCenter, p0), N); - if (XMVectorGetX(Dist) > 0) - { - continue; - } + //if (XMVectorGetX(Dist) > 0) + //{ + // continue; + //} // If the center of the sphere is farther from the plane of the triangle than // the radius of the sphere, then there cannot be an intersection. @@ -2890,12 +2890,13 @@ namespace wiScene bool intersects = XMVector4EqualInt(XMVectorAndCInt(Intersection, NoIntersection), XMVectorTrueInt()); - if (intersects && bestDist < result.distance_to_polygon) + if (intersects) { result.entity = entity; result.depth = sphere.radius - XMVectorGetX(XMVector3Length(vCenter - bestPoint)); XMStoreFloat3(&result.position, bestPoint); XMStoreFloat3(&result.normal, XMVector3Normalize(vCenter - bestPoint)); + return result; } } subsetCounter++; diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index eecf414e3..0c4fced06 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -1360,7 +1360,6 @@ namespace wiScene XMFLOAT3 position = XMFLOAT3(0, 0, 0); XMFLOAT3 normal = XMFLOAT3(0, 0, 0); float depth = 0; - float distance_to_polygon = FLT_MAX; }; SceneIntersectSphereResult SceneIntersectSphere(const SPHERE& sphere, uint32_t renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0, const Scene& scene = GetScene()); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index a7a87e431..97925679b 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 39; // minor bug fixes, alterations, refactors, updates - const int revision = 72; + const int revision = 73; long GetVersion() diff --git a/scripts/character_controller_tps.lua b/scripts/character_controller_tps.lua index 7df43ad26..c15738d9c 100644 --- a/scripts/character_controller_tps.lua +++ b/scripts/character_controller_tps.lua @@ -194,14 +194,15 @@ Character = { self.state_prev = self.state -- gravity: - self.force = vector.Add(self.force, Vector(0,-9.8 * 10,0)) + self.force = vector.Add(self.force, Vector(0,-9.8 * 20,0)) -- apply force: self.velocity = vector.Add(self.velocity, vector.Multiply(self.force, 0.016)) self.force = Vector(0,0,0,0) -- Sphere collider for character: - local sphere = Sphere(vector.Add(model_transform.GetPosition(), Vector(0,1.1)), 1) + local radius = 0.7 + local sphere = Sphere(vector.Add(model_transform.GetPosition(), Vector(0,radius)), radius) local pp = sphere.GetCenter() local intersection = false local ccd = 0 @@ -225,13 +226,13 @@ Character = { self.velocity = vector.Multiply(desiredMotion, velocityLen) intersection = true - sphere.SetCenter(prevpos) + sphere.SetCenter(vector.Add(sphere.GetCenter(), vector.Multiply(n2, depth))) -- remove penetration end end --DrawPoint(sphere.GetCenter(), 0.5, Vector(0,1,0,1)) if intersection then - self.velocity = vector.Multiply(self.velocity, 0.8) -- ground friction + self.velocity = vector.Multiply(self.velocity, 0.87) -- ground friction else self.velocity = vector.Multiply(self.velocity, 0.94) -- air friction end