Random Point on BoundingBox Perimeter

Glad to help in the brainstorming process!
There are always a lot of ways of achieve a goal and
I am sure there are many better than this one but hey! it works :slight_smile:

instead of nested If conditions you can use switch like this:

switch (RandomDirection)
{
case 0:

	// top
	OffsetY = UKismetMathLibrary::RandomFloatInRange(-ScaledBoxBounds.Y, ScaledBoxBounds.Y);
	OffsetZ = ScaledBoxBounds.Z;

case 1:

	// right
	OffsetY = ScaledBoxBounds.Y;
	OffsetZ = UKismetMathLibrary::RandomFloatInRange(-ScaledBoxBounds.Z, ScaledBoxBounds.Z);

case 2:

	// left
	OffsetY = -ScaledBoxBounds.Y;
	OffsetZ = UKismetMathLibrary::RandomFloatInRange(-ScaledBoxBounds.Z, ScaledBoxBounds.Z);

default:

// bottom
	OffsetY = UKismetMathLibrary::RandomFloatInRange(-ScaledBoxBounds.Y, ScaledBoxBounds.Y);
	OffsetZ = -ScaledBoxBounds.Z;

}






Greetz!
Dany

1 Like