Pages

quinta-feira, 27 de abril de 2017

BP Compendium 3: Random Point in Bounding Box

Random Point in Bounding Box


A function that returns a vector representing a random point located within a volume specified by a origin point and a "Box Extent".

Input

  • Origin:  Vector representing the central position of the "Box Extent".
  • Box Extent: Vector that contains the dimensions of the box that defines the 3D volume.

Output

  • Return Value: Vector representing a point that was generated randomly inside the "Box Extent" informed.


Example Usage: 

The image below is from a "Level Blueprint". A "Box Trigger" named "SpawnArea" has been placed on the level to define an area where items will be created at random positions within this area. When the game starts, the "ForLoop" action repeats the "SpawnActor" action 20 times to create 20 items in random positions. The position of each item is obtained with the "Random Point in Bounding Box" function using the "Origin" and "Box Extent" of the "SpawnArea".

Click to enlarge

The "SpawnActor" action needs a "Transform" type structure to apply to the actor that will be created. When trying to connect a vector to a "Transform" the editor automatically creates a converter using the vector as "Location". The other attributes of the "Transform" are set to their default values.

In the "Collision Handling Override" parameter of "SpawnActor" the "Try to Adjust Location, But Always Spawn" option was used. This causes the "SpawnActor" to check for any obstacles in the position where the actor will be created. If there is an obstacle, the actor will be moved to a nearby free location.