From 9c751a70338c7488553548bb62b1e28c2b230186 Mon Sep 17 00:00:00 2001 From: Axel Date: Thu, 13 Oct 2022 13:01:08 +0200 Subject: [PATCH] Fixed bone rotation for vegetation --- .../Carla/Vegetation/SpringBasedVegetationComponent.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp index 36c60dc0b..478aea9e2 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vegetation/SpringBasedVegetationComponent.cpp @@ -400,7 +400,9 @@ void USpringBasedVegetationComponent::GenerateCollisionCapsules() UCapsuleComponent* Capsule = NewObject(GetOwner()); Capsule->AttachToComponent(SkeletalMesh, FAttachmentTransformRules::KeepRelativeTransform, FName(*Joint.JointName)); Capsule->RegisterComponent(); - FTransform CapsuleTransform(FRotator(90, 0, 0), Bone.CenterOfMass, FVector(1,1,1)); + // create rotation from z direction to align the capsule + FRotator BoneRotation = UKismetMathLibrary::MakeRotFromZ(Bone.CenterOfMass.GetSafeNormal()); + FTransform CapsuleTransform(BoneRotation, Bone.CenterOfMass, FVector(1,1,1)); Capsule->SetRelativeTransform(CapsuleTransform); Capsule->SetCapsuleHalfHeight(Bone.Length*0.5f); Capsule->SetCapsuleRadius(6);