Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

This recipe uses the vehicle asset from the HRDP Auto Showroom Template available from Unity (https://blogs.unity3d.com/2021/01/29/take-a-ride-with-the-auto-showroom-sample-template-and-volvo-xc40-recharge/).

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: https://docs.unity3d.com/Manual/PrefabVariants.html. 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: choose “Prefab Variant.”

Let’s make a couple of changes to this prefab:

  • Disable the Collider object. These colliders interfere with the door colliders which prevents the Grabbable and Hinge Joint from working properly.

  • Disable the “Car Door” script on the base of the prefab. This script takes over control of the door rotation which prevents the door from opening.

Make Door_Front_LH Grabbable

Right-click and choose “Make Grabbable” from the Motive menu.

Add Hinge Joint

Motive > Joints > Add Hinge Joint. Note that the door rotates around the Y axis. Scroll down to the Hinge Joint component and adjust the axes:

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. Let’s add a Rigidbody to the Body node. Mark the Rigidbody as Kinematic.

Then connect this Rigidbody to “Connected Rigidbody” field on the Hinge Joint.

Add a Handle

The final step for this phase is to add a handle so that the physics works properly. Add an empty object to Door_Front_LH and rename it “Handle.” Drag it into position so that it lines up with the handle.

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

And finally for the Grabbable, make this Handle the “Grab Point”:

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.

Note that the Lower/Upper rotation is determined by the Axis and Secondary Axis. With this configuration, the door is open at the Lower Rotation stop (-60) and closed at the upper rotation (0).

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.)

The “Bump” effect is included in the SDK.

  • No labels