I have a pawn/actor that is a sphere (a snowball). When I roll on snow, it grows (I scale it and add mass).
Problem: I have a weird behavior, my ball rolls but sometimes "jumps" (or bounce up).
The reason seems to be that the ball become bigger and overlap with the ground, causing a big collision.
I tried to change it's position with an offset (Ball->SetAllPhysicsPosition(Ball->RelativeLocation + FVector(0, 0, newRadius-pastRadius);
, but I still have the same problem. (It "works" with a big hardcoded offset, but not with any size).
Would you have an idea on how to fix this behavior?
This is the code I use to make the ball gets bigger. I add torque to move it around.
void ASnowballBall::NotifyHit(...)
{
float resizeValue = 0.0f;
//If the snowball collides with snow, it grows
if (Other->GetName().StartsWith("Snow", ESearchCase::IgnoreCase) && Ball->BodyInstance.GetUnrealWorldVelocity().Size() > 50.0f)
{
// Max size based on mass
if (Ball->GetMass() < 10000.0f){
resizeValue = (20.0f / Ball->GetMass()));
resizeValue = FMath::Clamp(resizeValue, 0.0f, 0.003f);
Ball->SetRelativeScale3D(Ball->RelativeScale3D + resizeValue);
Ball->SetMassScale("None", Ball->BodyInstance.MassScale);
}
}