fix(vehicle): settle the chassis on the road (float 33 m -> 6 cm)
Two root causes, both in how the chassis box was authored: 1. The box centre was -Extent.Z*0.25, below the root bone, so the box sat under the ground and the suspension pushed the whole vehicle up. The skeletal mesh imports ROLLED (height along Y, width along Z) while the armature is unrolled, so the box is now built with swapped axes (length from mesh X, width from mesh Z, height from mesh Y) and centred at the rolled mesh's mid-height (Bounds.Origin.Y). The vehicle now settles at Z 6 cm instead of floating at 33 m. 2. A left-over diagnostic stopped the movement component at 2.5 s whenever the pawn ticked, which cut the drive test (throttle runs 1-4 s). It is now gated on the vehicle actually having zero wheels. Remaining: the drive test still reports ~0 forward speed, so the throttle does not yet move the car - the wheels rest ~2 cm above the ground because the suspension rest position is measured against the root bone while the box sits at the centre of mass.
This commit is contained in:
1 parent
84291a5270
commit
319096d0d9
5 files changed
+25
-19
No files matched your search
@@ -445,19 +445,22 @@ void AGigLineVehicle::Tick(float DeltaSeconds)
|
||||
// If the Chaos vehicle never came into existence (no wheels), its movement component has no
|
||||
// valid state to drive, and continuing to tick it writes whatever is in that empty state back
|
||||
// onto the actor - which is the only explanation that fits a still body and a moving actor.
|
||||
// Only stop in that case: with real wheels the mover must keep ticking to drive, and stopping
|
||||
// it at 2.5 s was what killed the drive test (throttle runs 1-4 s).
|
||||
if (!bMoverStopped && SettleElapsed > 2.5f)
|
||||
{
|
||||
bMoverStopped = true;
|
||||
if (const UChaosWheeledVehicleMovementComponent* WheelComp =
|
||||
Cast<UChaosWheeledVehicleMovementComponent>(GetVehicleMovementComponent()))
|
||||
const UChaosWheeledVehicleMovementComponent* WheelComp =
|
||||
Cast<UChaosWheeledVehicleMovementComponent>(GetVehicleMovementComponent());
|
||||
if (!WheelComp || WheelComp->Wheels.Num() == 0)
|
||||
{
|
||||
bMoverStopped = true;
|
||||
UE_LOG(LogTemp, Warning,
|
||||
TEXT("GigLine vehicle: stopping the mover - wheels=%d at Z %.0f"),
|
||||
WheelComp->Wheels.Num(), GetActorLocation().Z);
|
||||
}
|
||||
if (UMovementComponent* Mover = GetVehicleMovementComponent())
|
||||
{
|
||||
Mover->SetComponentTickEnabled(false);
|
||||
WheelComp ? WheelComp->Wheels.Num() : -1, GetActorLocation().Z);
|
||||
if (UMovementComponent* Mover = GetVehicleMovementComponent())
|
||||
{
|
||||
Mover->SetComponentTickEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,14 +53,17 @@ UPhysicsAsset* UGigLineVehicleBuilder::BuildPhysicsAsset(USkeletalMesh* Mesh,
|
||||
// A box slightly under the mesh bounds: a body that is exactly the bounds sits on the
|
||||
// ground plane and reads as floating because the mesh has wheels below the sills.
|
||||
FKBoxElem Box;
|
||||
// The skeletal mesh imports ROLLED (height along Y, width along Z) while the armature is
|
||||
// unrolled (height Z, width Y). The box is a body on the root bone, so it must be built in
|
||||
// the UNROLLED frame: length from mesh X, width from mesh Z, height from mesh Y.
|
||||
Box.X = Extent.X * 1.9f;
|
||||
Box.Y = Extent.Y * 1.8f;
|
||||
Box.Z = Extent.Z * 0.55f;
|
||||
// The chassis body must sit ABOVE the ground (the car body is at Z 0..height), not below
|
||||
// the root bone. The old -Extent.Z*0.25 put the box below the ground and the suspension
|
||||
// (measured against the root bone) then pushed the chassis upward. Place it at the car's
|
||||
// mid-height instead.
|
||||
Box.Center = FVector(0.f, 0.f, Extent.Z * 0.35f);
|
||||
Box.Y = Extent.Z * 1.8f;
|
||||
Box.Z = Extent.Y * 0.55f;
|
||||
// The chassis sits at the car's centre of mass, which is the rolled mesh's mid-height
|
||||
// (Bounds.Origin.Y) mapped onto the unrolled height axis (Z). The suspension rest position is
|
||||
// measured against the root bone (the grounded origin), so the box must sit at the centre of
|
||||
// mass rather than the root bone - this is what settled the vehicle on the road.
|
||||
Box.Center = FVector(0.f, 0.f, Bounds.Origin.Y);
|
||||
Body->AggGeom.BoxElems.Add(Box);
|
||||
PhysicsAsset->SkeletalBodySetups.Add(Body);
|
||||
|
||||
|
||||
Reference in new issue
Block a user