9 Dec 2020 16:12

Object interation at runtime

Below are some videos from early experiments into object interaction in Unreal Engine. Thanks to the fantastic Line Trace By Channel and Line Trace For Objects nodes, finding actors and components in a scene through a line trace is fairly straight forward.

Experiment 1

Casting a line trace from the camera and sticking a sphere to any "hit" actors.

In this experiment, when a key is pressed, a tracing line is projected from the camera outwards into the scene in the direction of the mouse location. As soon as the line trace function detects an object, the location of the "hit" is used to position a sphere.

Experiment 2

Interacting with "hit" actors by changing their colours and causing physics impulses.

This second experiment built on the previous success of finding a "hit" and using its location. Here the actual hit actor is influenced by setting a new material on the mesh (with a random colour) and in the case of it being one of the cubes, a vertical impulse giving it a bit of a jump.

Experiment 3

Visualising line traces as visible rays for debugging.

To get a better visual understanding of the trace result, the tracing nodes can also create a visual line in the scene (editor/dev only). Note how the representations are red squares until the camera is moved. This helps us see that the projected output is coming directly from the camera's position at the time of the "hit" even.