UE4 learning experience: a simple application of the Scene Component blueprint

Scene Component is a less commonly used category in the blueprint class (especially for novices), mainly because the functions it implements can be implemented in the same way in the Actor class, making it a bit redundant.

After using this class, the author found that its function is more equivalent to an interface, which can be called by other blueprint classes, and the operation method is simple, and the effect is obvious after implementation. Here is a simple application for readers to understand and use this blueprint class.

Ready to work

The first is to create a Scene Component blueprint class named HoverComponent.

 

Next is the work before writing the blueprint logic: Create two Float variables named TraceLength and HoverForce, the former is used to adjust the amplitude of the object when it floats, and the latter represents the pressure the object is subjected to when it floats. The initial value of TraceLength is set to 150, and this variable can be set as a public variable to facilitate real-time changes in the game; the initial value of HoverForce is set to 500000.

event scheduling

 

The above nodes implement the initial value setting of Component and the setting of simulated physical effects.

Then call the Event Tick event to perform ray detection in each frame of the game. The detection direction is the Z-axis direction of the object, and the amplitude is the previously set TraceLength

After the detection result is exposed, the normal phase direction collision vector and the position vector are subjected to simple operations to obtain the object floating force vector, which is added to the Component

Finally, set the linear damping and angular damping of the Component, so a simple object floating effect blueprint is completed.

practical testing

Create a Cube or Sphere static object component in the level, select it and add the HoverComponent made above in the Detail panel, change the movement property of the object to Movable, place the Cube or Sphere in the scene, run the level, and test, You can change the value of TraceLength in Default to see the effect

 The author's test results are shown in the following figure

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325619903&siteId=291194637