Improved collision behaviour

This commit is contained in:
Axel 2022-11-04 12:14:29 +01:00 committed by bernat
parent d348dc51ee
commit feea507901
2 changed files with 40 additions and 27 deletions
Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation

View File

@ -301,7 +301,7 @@ void USpringBasedVegetationComponent::GenerateSkeletonHierarchy()
}
}
// UpdateGlobalTransform();
UpdateGlobalTransform();
}
void USpringBasedVegetationComponent::BeginPlay()
@ -352,7 +352,7 @@ void USpringBasedVegetationComponent::GenerateCollisionCapsules()
{
for (FSkeletonBone& Bone : Joint.Bones)
{
if (Bone.Length < 0.01f)
if (Bone.Length < MinBoneLength)
{
continue;
}
@ -619,8 +619,8 @@ void USpringBasedVegetationComponent::ResolveContactsAndCollisions(
if (!IsValid(Capsule))
continue;
const FVector CapsuleLocation = Capsule->GetComponentLocation();
const FVector PrimitiveLocation = Primitive->GetComponentLocation();
static constexpr float MIN_DISTANCE = 1.0f;
FVector PrimitiveLocation = Primitive->GetComponentLocation();
PrimitiveLocation = PrimitiveLocation + Primitive->GetUpVector()*VehicleCenterZOffset;
FVector ClosestPointOnCapsule;
float DistanceOnCapsule;
FHitResult HitResult;
@ -637,6 +637,10 @@ void USpringBasedVegetationComponent::ResolveContactsAndCollisions(
LineTraceStart, LineTraceEnd, FCollisionQueryParams());
ClosestPointOnCollider = HitResult.Location;
DistanceToCollider = (ClosestPointOnCollider - ClosestPointOnCapsule).Size();
if (DebugEnableVisualization)
{
DrawDebugLine(GetWorld(), LineTraceStart, LineTraceEnd, FColor::Orange, false, 0.1f, 0.0f, 1.f);
}
}
if(!HitFound)
{
@ -651,7 +655,7 @@ void USpringBasedVegetationComponent::ResolveContactsAndCollisions(
DrawDebugSphere(GetWorld(), ClosestPointOnCapsule, DEBUG_SPHERE_SIZE, 64, FColor(255, 0, 255, 255));
DrawDebugSphere(GetWorld(), ClosestPointOnCollider, DEBUG_SPHERE_SIZE, 64, FColor(255, 0, 255, 255));
DrawDebugSphere(GetWorld(), CapsuleLocation, DEBUG_SPHERE_SIZE, 64, FColor(255, 255, 255, 255));
DrawDebugSphere(GetWorld(), PrimitiveLocation, DEBUG_SPHERE_SIZE, 64, FColor(0, 0, 0, 255));
DrawDebugSphere(GetWorld(), PrimitiveLocation, DEBUG_SPHERE_SIZE, 64, FColor(255, 255, 255, 255));
}
const int JointId = CapsuleToJointId[Capsule];
@ -785,9 +789,9 @@ void USpringBasedVegetationComponent::SolveEquationOfMotion(
float beta = Beta;
float alpha = Alpha;
Eigen::Matrix3d K;
K << SpringStrength,0.f,0.f,
0.f,SpringStrength,0.f,
0.f,0.f,SpringStrength;
K << SpringStrength*SpringStrengthMulFactor.X,0.f,0.f,
0.f,SpringStrength*SpringStrengthMulFactor.Y,0.f,
0.f,0.f,SpringStrength*SpringStrengthMulFactor.Z;
Eigen::LLT<Eigen::Matrix3d> lltofI (I);
Eigen::Matrix3d L = lltofI.matrixL();
Eigen::Matrix3d Linv = L.inverse();

View File

@ -210,58 +210,67 @@ private:
std::vector<FJointCollision> JointCollisionList;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
USkeletalMeshComponent* SkeletalMesh;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
TArray<UPrimitiveComponent*> BoneCapsules;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
TMap<UPrimitiveComponent*, int> CapsuleToJointId;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float Beta = 0.5f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float Alpha = 0.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
FVector Gravity = FVector(0,0,-1);
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float BaseSpringStrength = 10000.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float MinSpringStrength = 2000.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float HorizontalFallof = 0.1f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float VerticalFallof = 0.1f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float RestFactor = 0.5f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float DeltaTimeOverride = -1.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float CollisionForceParameter = 10.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float CollisionForceMinVel = 1.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float ForceDistanceFalloffExponent = 1.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float ForceMaxDistance = 180.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float MinForceFactor = 0.01;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float LineTraceMaxDistance = 180.f;
UPROPERTY(EditAnywhere, Category = "Spring Based Vegetation Component")
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float CapsuleRadius = 6.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float MinBoneLength = 10.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
FVector SpringStrengthMulFactor = FVector(1,1,1);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
float VehicleCenterZOffset = 120.f;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")