Skip to content

Commit

Permalink
Merge pull request #93 from Xaleros/master
Browse files Browse the repository at this point in the history
 StepDown/Move after StepUp/Move in UActor::TickWalking(), fixing collision issues
  • Loading branch information
dpjudas authored Feb 11, 2024
2 parents 34d236f + 0bd384c commit c65d4b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions SurrealEngine/Collision/TraceCylinderLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ CollisionHitList TraceCylinderLevel::Trace(ULevel* level, const vec3& from, cons

if (traceWorld)
{
dvec3 extents = { (double)radius, (double)radius, (double)height };
if (extents == dvec3(0.0, 0.0, 0.0))
if (radius == 0.0 && height == 0.0)
{
// Line/triangle intersect
TraceRayModel tracemodel;
Expand All @@ -75,6 +74,7 @@ CollisionHitList TraceCylinderLevel::Trace(ULevel* level, const vec3& from, cons
{
// AABB/Triangle intersect
TraceAABBModel tracemodel;
dvec3 extents = { (double)radius, (double)radius, (double)height };
CollisionHitList worldHits = tracemodel.Trace(Level->Model, origin, tmin, direction, tmax, extents, visibilityOnly);
hits.push_back(worldHits);
}
Expand Down
15 changes: 15 additions & 0 deletions SurrealEngine/UObject/UActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,16 @@ void UActor::TickWalking(float elapsed)
{
vec3 moveDelta = vel * timeLeft;

// step up first
TryMove(stepUpDelta);
CollisionHit hit = TryMove(moveDelta);
timeLeft -= timeLeft * hit.Fraction;
moveDelta = vel * timeLeft;

// step back down so we don't bump our heads
TryMove(stepDownDelta);
hit = TryMove(moveDelta);
timeLeft -= timeLeft * hit.Fraction;

if (hit.Fraction < 1.0f)
{
Expand Down Expand Up @@ -2505,3 +2512,11 @@ void UDecal::DetachDecal()
++it;
}
}

/////////////////////////////////////////////////////////////////////////////

double UMover::TraceTest(ULevel* level, const dvec3& origin, double tmin, const dvec3& direction, double tmax, double height, double radius)
{
// Default cylinder
return level->Hash.CylinderActorTrace(origin, tmin, direction, tmax, height, radius, this);
}
2 changes: 2 additions & 0 deletions SurrealEngine/UObject/UActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,8 @@ class UMover : public UBrush
public:
using UBrush::UBrush;

virtual double TraceTest(ULevel* level, const dvec3& origin, double tmin, const dvec3& dirNormalized, double tmax, double height, double radius);

vec3& BasePos() { return Value<vec3>(PropOffsets_Mover.BasePos); }
Rotator& BaseRot() { return Value<Rotator>(PropOffsets_Mover.BaseRot); }
uint8_t& BrushRaytraceKey() { return Value<uint8_t>(PropOffsets_Mover.BrushRaytraceKey); }
Expand Down

0 comments on commit c65d4b8

Please sign in to comment.