Touch Screens - MOARdV/AvionicsSystems GitHub Wiki

NOTE: This document is very, very incomplete.

The COLLIDER_ADVANCED MASComponent feature allows for the emulation of touch-enabled props.

The basic COLLIDER_EVENT reports click and release actions, and it can report mouse drag activity, it can not provide information on where within the collider the mouse clicked, or where within collider the mouse was dragged while the button was held.

The Advanced Collider detects where within the Unity BoxCollider the "collision" happened when the mouse was clicked, and it knows where within the bounds the mouse was moved while it was held. Because there's more information available, configuring a prop to use an advanced collider is a little more involved than configuring a prop for the basic Collider Event.

Adding the Touch Collider

One advantage of the modular design of the ASET Props is that there is model that consists of only a single collider. This model, ASET/ASET_Props/Control/Push_Button_Modular/models/pb_Collider, can be used to retrofit touch awareness to any existing prop (with a little bit of effort). Adding this collider is as simple as adding this to the prop's config:

MODEL
{
  model = ASET/ASET_Props/Control/Push_Button_Modular/models/pb_Collider
  scale = 1, 1, 1
  position = 0, 0, 0
}

When you load the prop in Unity, you'll see the unscaled pb_Collider, which very likely won't be scaled correctly (and maybe not positioned correctly). If you have access to the prop mesh you want to add this collider to, you can probably figure out the right scale and position to use fairly easily. Otherwise, you will need to tweak the scale until it covers the region. For instance, when enabling touch control of the Indicator Advanced props, I settled on this values:

MODEL
{
  model = ASET/ASET_Props/Control/Push_Button_Modular/models/pb_Collider
  scale = 0.8, 1, 2.7
  position = 0, 0, -0.009
}

This positions the touch collider so it's a little smaller vertically than the display region, so that the touch-enabled region maps to where the numeric display moves within the indicator. I also had to shift the collider "up" relative to the face of the indicator to center the collider within the gauge's bounds.

Fortunately, this step is fairly quick to iterate, since it can be done in Unity - add the prop to an IVA, figure out which adjustments you need, save the config, reload the props through KSP Part Tools, add a new copy of the prop (so that the collider scale / position are updated). Repeat until you have it where you want it.

Once you've got the collider positioned correctly in the model, it's time to add the COLLIDER_ADVANCED to the MASComponent module.

Adding COLLIDER_ADVANCED