Rotation from normal ?

Yay! It’s Working!

Thank you again Stormharrier, you rock!

Never worked with quaternions before and I’m not sure I understand 100% what I did, but here’s the code in case someone wants to take a look :



FVector UpVector = MyRootComponent()->GetUpVector();
FVector NormalVector = Hit.ImpactNormal;

FVector RotationAxis = FVector::CrossProduct(UpVector, NormalVector);
RotationAxis.Normalize();

float DotProduct = FVector::DotProduct(UpVector, NormalVector);
float RotationAngle = acosf(DotProduct);

FQuat Quat = FQuat(RotationAxis, RotationAngle);
FQuat RootQuat = MyRootComponent()->GetComponentQuat();

FQuat NewQuat = Quat * RootQuat;

MyRootComponent()->SetWorldRotation(NewQuat.Rotator());


4 Likes