Objective:

  • When the hand is selecting gesture, cast a ray
  • If the ray hits an object, highlight the object to represent "it is selected"
  • When the hand is confirm gesture, destroy the ray, de-highlight the selected object
  • Usage: only after an object is selected can it be modified

Implementation Steps

  1. When hand gesture is selecting gesture (in our example is Gun gesture, can also be other gestures, only requirement is index finger point out), begin selecting.
  2. Cast a blue ray from index finger base to index finger tip, and extend to infinity far.
  3. If the ray hits an object (use tag to distinguish with other colliders like ground and walls), change the ray color to green; record original color and shader of the selected object, change to highlight color and shader, indicating it is selected.
  4. When hand gesture is confirm gesture (in our example is OK gesture), the object is de-selected, change its color and shader to original.
  5. Trick during implementation: after hit by ray and before confirmed, the object is selected but the hand gesture might not be the selecting gesture, so the "isSelected" status should be saved as an independent boolen instead of directly related to selecting gesture.

Demo video of selecting and highlighting an object

The demo video shows:

  • The hand uses select gesture to cast a ray.
  • Ray changes color when it hits a design object.
  • A design object is highlighted to indicate it is selected.
  • The design object is de-highlighted when the hand is confirm gesture.
  • When a design object is selected and the hand casts ray on a second design object, the first object is auto de-selected, and the second object is selected and highlighted.

Next Post Previous Post