How to make a functional plane's gas lever?

Ok… Lets see if this makes sense:

  1. The setup:
  • LevelPivot is a scene component I’m using to hold the handle. More on it later.
  • Everything else is just a static mesh component but the text.
  • The CollisionCyndiler is a normal cylinder that has visible set to false leaving only the collision. This will help us get a location from the mouse trace that is spherical to the center (LevelPivot). this is what the cylinder looks like with visible set to true:
  1. Enable Click Events:
    image

  2. To activate, player has to click the handle:

  • The actor has tick disabled by default. It’s only activated when clicked.
  • We need to enable Input on this actor because it needs to listen when the player releases LMB to stop working.
  • Notice I change the handle collision response to visibility: this is so the mouse trace only hits the cylinder. Helps get a smooth rotation of the handle when following the mouse.
  1. To disable the BP:
  • The purpose of the bool is to block the LMB input if ithe player releases without clicking on the handle first. This is not necesarry since Input is disabled anyways…
  • Disable tick and disable input for this actor so it stays static.
  • We set handle collision back to block so it can be triggered again.
  1. Not much to explain here:
  • First is we transform the mouse hit location to relative. This will make the lever work no matter how it is oriented in world space.
  • We clamp the level to our desired limits.
  • Map Range Clamped allows to map a range to what ever other range you want.

Result:
Levers

4 Likes