Core/Math API – Rotation using FRotationMatrix to have one object face another

FRotationMatrix offers matrix construction using a series of ::Make* routines. They are easy to use and useful to get one object to face another. Say you have two objects, one of which is following the other. We want the rotation of the follower to always be facing what it is following. The construction methods of FRotationMatrix make this easy to do.

Getting ready

Have two actors in a scene, one of which should face the other.

How to do it…

  1. In the follower's Tick() method, look into the available constructors under the FRotationMatrix class. Available are a bunch of constructors that will let you specify a rotation for an object (from stock position) by reorienting one ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.