Using your device’s Gyroscope to rotate an Actor

 

Snap, does anyone remember these mechanics? I do and I loved them. For those who are not familiar with them, check out the modern way to How To Make a Cardboard Box Marble Labyrinth Game Video. Awesome.

As you can imagine, we’re not cutting cardboards but use this game’s idea in a Blue Print to rotate an Actor (the plane).

Idea

Yeah, you get the idea.
We’re working with the Gyroscope via Unreal Engine’s high-level implementation: Tilt.

Basic Setup

We actually only have to take care of two things:

  • Translate these inputs to a Rotator relative to your Actor
  • Understand Tilt-Input

 

Find your Axes

So, in order to get this straight, you have to look at your Actor itself and around which axes (yeah, that’s apparently the plural of axis) you want to rotate. In my case, it was only the X and the Y. The following image shows you why. We do not want to rotate the board in our hands, just tilt it. Btw. thanks UE4 for reflecting my gizmo. Really .. helps, I guess 🙂

 

Understanding the Tilt Vector

The Tilt Motion Input returns a vector, which is understandable as a Rotator, consisting of:

  • Roll
  • Pitch
  • Yaw

The incoming values are relative, pretty much the same as the Rotation Rate, which we’ve already used in this article. We only have to figure which axis belongs to which input value. To demonstrate this, I’ve added a picture. If you’re laying down your phone on a table like this, the Z axis is represented by the rotation you’d apply to set it as portrait towards you. Eventually we’re not going to use it.

Blueprint

Note: There has to be a re-routing from the incoming Z axis to UE4’s Rotator Y axis. I have yet to find out why, but it simply seems like a mistitled pin connection in the BP Editor.

Since the incoming values are ranged -1 to 1, we’re multiplying them by 10 to get a little more response from them. This mainly depends on your scene size, camera position, etc. For me, 10 felt good.

Finally, I figured I had to multiply the Pitch by a negative value, because .. yeah, I don’t know, people aren’t sure about what the default orientation of the iPhone itself is, I guess. Check this if you’re interested, otherwise, this Mulitpy Vector node is the one to touch if things are mirrored.

Happy build!

 

3 thoughts to “Using your device’s Gyroscope to rotate an Actor”

    1. hey ahmed,
      on iOS it pretty much looks the same except for the post processing which i’ve only added to the desktop-version.
      i will be posting an article soon with the HDRI (high dynamic range imaging) setup and how to get things settled for mobile, too.

  1. Hi there!
    I’m working on a maze with a motion-controlled floor, instead of a motion controlled ball. However, I’m running into issues with collision with a pawn and a required skeletal mesh for a character. To my understand, base actors can’t receive input through a game mode. Can you explain more how you set up your actor shown in the video? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*