{Tutorial} How to Put the User Inside a Car!
Hi Lens Community,
Today, I’ll show you how to add a car to your lens and give the effect that the user is sitting in the car, by attaching the vehicle to the user’s shoulder and using device tracking to show the car in the back camera!
The first step is to get your 3D model of a car. Once you do that, drag the file into Lens Studio. Now, let’s attach the car to the shoulders so it always looks like you’re sitting in the driver’s seat. To do this, add a script in the resources panel and copy and paste the following provided by Brandon / Apoc
var obj = script.getSceneObject()
var o = obj.getTransform().getWorldRotation()
var event = script.createEvent("UpdateEvent");
event.bind(function(eventData) {
obj.getTransform().setWorldRotation(o)
});
Next, drag this script under the head binding and drag the face occluder under this script. After this is done, click on your car 3D model and add a component and select “pin to mesh." Then pin it to the face occluder. This way, even when the head is out of frame, your car does not disappear. You can now drag and scale your model around to make it's perfect so the user always sits in the driver’s seat. Now your car will follow the user around so it’s always in the same place, but it won't rotate around with the head binding.
Lastly, click on your camera and click “add component” and add a device tracking component. Then, select “rotation” as the tracking mode. This is so that even on the back camera, it will still give the look that the user is inside of the car. You can test this out by clicking “interactive env” as the preview type. After you do this, you can right click to move around and simulate the user’s phone moving around.
Done! Your user now is inside your 3D car!
Enjoy!