Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
panelIconId1f393
panelIcon:mortar_board:
panelIconText🎓
bgColor#4C9AFF

In depth learning on Scene Configuration can be found in this course in Motive Academy.

This recipe uses the vehicle asset from the HRDP Auto Showroom Template available from Unity

...

.

Table of Contents
minLevel1
maxLevel6
outlinefalse
typelist
printablefalse

Setup

It’s always useful to make a copy of the original

...

Prefab when you are going to make changes. We generally recommend using

...

Prefab Variants. In this case, with the

...

Scene open, drag the XC40_Recharge Prefab object from your

...

Scene into a new folder called “Props.” You will be asked whether you want to create a

...

Variant.

1. Choose Prefab Variant:

Image Modified

Let’s make a couple of changes to this

...

Prefab:

  1. Disable the Collider object. These

...

  1. Colliders interfere with the door

...

  1. Colliders which prevents the Grabbable and Hinge Joint from working properly

...

  1. :

Image Modified

  1. Disable the

...

  1. Car Door script on the base of the prefab. This

...

  1. Script takes over control of the door rotation which prevents the door from opening

...

  1. :

Image Modified

Step 1: Make Door_Front_LH Grabbable

  1. Right-click and choose

...

  1. Make Grabbable from the Motive menu

...

  1. :

Image Modified

Step 2: Add Hinge Joint

  1. Motive > Joints > Add Hinge Joint. Note that the door rotates around the Y axis

...

  1. Scroll down to the Hinge Joint component and adjust the axes:

Image Modified

...

Image Added

Note that both Axis and Secondary Axis need to be updated since these two axes need to be perpendicular to each other.

Next let’s take care of the warning on the Hinge Joint. The joint needs to connect to another Rigidbody.

...

  1. Add a Rigidbody to the Body node

...

  1. Mark the Rigidbody as Kinematic

...

  1. :

Image Modified
  1. Then connect this Rigidbody to

...

  1. Connected Rigidbodyfield on the Hinge Joint

...

  1. :

Image Modified

Step 3: Add a Handle

The final step for this phase is to add a handle so that the physics works properly.

  1. Add an empty object to Door_Front_LH and rename it

...

  1. Handle

  2. Drag it into position so that it lines up with the handle

...

  1. :

Image Modified
  1. Now add a Capsule Collider to the handle to make it interactible

...

  1. :

Image Modified
  1. And finally for the Grabbable, make this Handle the

...

  1. Grab Point:

Image Modified

Step 4: Add Hinge Limits

Now you should be able to enter the scene and grab the door by the handle. The door will swing on the hinge, but you’ll notice that it can swing fully around the hinge with no limits. We can add limits to the Hinge Joint to make the door open and close properly

...

:

...

Image Added

Note that the Lower/Upper rotation is determined by the Axis and Secondary Axis.

...

The Hinge starts at Lower Rotation.

Step 5: Effects

Haptic feedback is important for these sorts of mechanical interactions. You can quickly add haptics to this movement by adding a Joint Effects component (see Joint Effects.)

Image Modified

The “Bump” effect is included in the SDK.

Step 6: Behaviour Model

As a final step, we can add a Behaviour Model to the door so that its state can be tracked in Storyflow. For more information about using Behaviour Models and Enums, click here. You can also learn more about Enums here.

  1. Make sure the door has a Motive Scene Object so that we can use it in Storyflow:

Image Added

We’ll track the Position as a value that can be in the Closed, Ajar, and Open states:

Image Added

We can use a Behaviour Model with an Enum state in Storyflow to track these states:

Image Added

Image Added

Usage example

  1. Activate a Behaviour Model Binding targeted at “Driver Side Front Door.” Use the (plus) shortcut to create a “Door Position” variable:

    Image Added

  2. Use a Variable Value Condition to check for the door being open:

Image Added

When you run this Script, the Screen Message should pop up when the user opens the door.

Related Articles