Let’s Make an AR App in 15 MINUTES!! (Beginner Friendly)
Summary
TLDRThis tutorial offers a step-by-step guide to creating an AR application in Unity, where users can scan an image to spawn a dragon and control its movement using a joystick. The video promises to teach the entire process within 15 minutes, covering software setup, Unity Hub installation, necessary modules, and package downloads. It guides viewers through project setup, scene creation, and scripting for image tracking and dragon control, concluding with a live demonstration of the AR application on an Android device.
Takeaways
- 😀 The video provides a step-by-step guide to creating an AR application where a dragon can be spawned by scanning an image and controlled using a joystick.
- 🛠️ Unity software is required for the development of this AR application, and the video instructs viewers to download and install Unity Hub and the specific version 2021.3.6.
- 📱 The tutorial emphasizes the need for specific modules like Android support, Android SDK, NDK tools, and Open JDK for successful Android application development.
- 🔍 The AR Foundation and AR Core XR Plugin are essential packages that need to be installed from the Unity Package Manager for AR functionality.
- 🐉 The dragon model and joystick pack are assets that are used in the application, and the video provides guidance on how to download and import them into the Unity project.
- 📸 An image is required for the AR image tracking feature, and the video explains how to set up the image tracking within the Unity project.
- 💻 The video demonstrates how to write scripts in Visual Studio to handle the spawning of the dragon prefab and the joystick control for moving the dragon within the AR environment.
- 🎮 The joystick control is implemented through a script called 'DragonController' that uses the Rigidbody component to move the dragon based on joystick input.
- 📱 The video concludes with instructions on how to build and run the AR application on an Android device, including enabling USB debugging and building the project.
- 🔧 Detailed settings adjustments in Unity, such as graphics API, multi-thread rendering, and scripting backend, are covered to ensure the application runs smoothly on Android devices.
Q & A
What is the main goal of the video?
-The main goal of the video is to guide viewers through the process of creating an AR application where they can scan an image to spawn a dragon and control its movement using a joystick, all within about 15 minutes.
What software is required to start the project?
-To begin the project, viewers need to have Unity software downloaded and installed, specifically the Unity Hub, which manages projects and different versions of the editor.
Why is Unity Hub used in this project?
-Unity Hub is used to manage all Unity projects and to handle different versions of the editor, as well as to add various modules required for specific project needs.
What is the significance of downloading the LTS release of Unity?
-The LTS (Long Term Support) release of Unity is significant because it is more stable, having fewer bugs, and any that exist are typically rectified by updates.
Which Unity version is recommended for this project?
-The recommended Unity version for this project is 2021.3.6, as it is the version the tutorial is based on, making it easier for the creator to assist with any issues.
What are the necessary modules for the project in Unity?
-The necessary modules for the project include Android build support, Android SDK and NDK tools, and Open JDK.
Why is the AR Foundation package important for this project?
-The AR Foundation package is crucial as it provides the necessary tools and components for building augmented reality applications in Unity.
What is the purpose of the AR Core XR Plugin in the project?
-The AR Core XR Plugin is used to enable augmented reality features specifically for Android devices, allowing the application to interact with the user's environment.
How does the image tracking work in the AR application?
-The image tracking in the AR application works by using the AR Tracked Image Manager component, which tracks a specific image and instantiates a prefab when the image is detected.
What is the role of the joystick pack asset in the project?
-The joystick pack asset is used to create a user interface element that allows the user to control the movement of the dragon within the AR environment.
How is the dragon prefab instantiated in the AR scene?
-The dragon prefab is instantiated when a tracked image is detected by the AR system. A script named 'Prefab Creator' is used to spawn the dragon prefab at the location of the detected image.
What settings are necessary for the Unity project to run on an Android device?
-For the Unity project to run on an Android device, settings such as graphics API, multi-thread rendering, scripting backend, and ARM 64 support need to be adjusted according to the script's instructions.
Why is it important to set the scripting backend to IL2CPP?
-Setting the scripting backend to IL2CPP is important for performance optimization and compatibility with certain Android devices.
How does the 'Dragon Controller' script enable movement in the AR application?
-The 'Dragon Controller' script enables movement by accessing the joystick's X and Y values to calculate a movement vector, which is then applied to the dragon's Rigidbody component to move it within the AR environment.
What is the final step to test the AR application on an Android device?
-The final step to test the AR application on an Android device is to connect the device to the computer, enable USB debugging, and build and run the project in Unity.
Outlines
🛠️ Setting Up Unity for AR Development
This paragraph outlines the initial steps for setting up Unity for AR application development. It emphasizes the need for downloading and installing Unity Hub, selecting the appropriate LTS release (2021.3.6), and installing necessary modules like Android support, Android SDK NDK tools, and Open JDK. The user is guided to create a new Unity project using the 3D core render pipeline and to name it 'AR Image Tracking.' The paragraph also instructs on downloading and importing necessary packages and assets such as AR Foundation, AR Core XR Plugin, a detectable image, a dragon model, and a joystick pack, all of which are crucial for the AR application being developed.
📱 Configuring Unity Project for Android
The second paragraph focuses on configuring the Unity project for Android development. It details the process of switching to the Android platform in the build settings, adjusting player settings to include the ARCore XR plugin, and ensuring the correct graphics API and scripting backend are selected. The paragraph also covers the creation of an image library for AR image tracking and the setup of an AR session origin with an AR tracked image manager component, which is essential for detecting and tracking the image used to spawn the dragon model in the AR environment.
🐉 Creating and Preparing the Dragon Prefab
This paragraph describes the process of creating and preparing the dragon prefab that will be spawned in the AR application. It involves resizing and positioning the dragon model, adjusting its animations to ensure it takes off and flies forward, and setting up the dragon prefab in Unity with the appropriate offset to account for its base and center. The paragraph also covers the creation of a new script called 'Prefab Creator' in Visual Studio, which is responsible for instantiating the dragon prefab when the image is detected by the AR system.
🕹️ Implementing Joystick Control for the Dragon
The fourth paragraph explains how to implement joystick control for the dragon in the AR application. It involves adding a joystick to the Unity scene, creating a 'Dragon Controller' script to manage the dragon's movement based on the joystick's input, and setting up the dragon prefab with a Rigidbody component for physics-based movement. The script calculates the movement direction based on the joystick's X and Y values, updates the dragon's velocity accordingly, and rotates the dragon to face the direction of movement. The paragraph concludes with instructions on adding the joystick to the scene, configuring it, and testing the application on an Android device.
Mindmap
Keywords
💡Unity
💡AR Foundation
💡AR Core
💡Joystick
💡Image Tracking
💡Prefab
💡Android SDK and NDK
💡Rigidbody
💡Scripting
💡Canvas
💡Build Settings
Highlights
Create an AR application to scan an image and spawn a dragon in about 15 minutes.
Download and install Unity software from unity.com/downloads.
Use Unity Hub to manage projects and editor versions.
Download LTS releases for stability in Unity editor versions.
Select Unity version 2021.3.6 for compatibility with the tutorial.
Install necessary modules: Android build support, Android SDK, NDK, and Open JDK.
Create a new Unity project with the 3D core render pipeline.
Download and import AR Foundation package version 4.2.6.
Install AR Core XR Plugin for Android.
Prepare resources: an image for detection, a dragon model, and a joystick pack.
Set up Unity project for Android platform with specific player settings.
Configure AR Core in the Android plugin management settings.
Create an AR scene by removing the main camera and adding XR components.
Add AR Tracked Image Manager to detect and spawn the dragon prefab.
Write a script to instantiate the dragon prefab when the image is detected.
Adjust dragon prefab size and animations for the AR experience.
Create and attach a Dragon Controller script for moving the dragon with a joystick.
Add a fixed joystick UI element to control the dragon's movement.
Build and run the AR application on an Android device.
Scan the prepared image with the app to spawn and control the dragon using the joystick.
Transcripts
and by the end of this video you would
have created an amazing air application
wherein you can scan an image to spawn a
dragon and move it around using a
joystick and the best part is that
you'll be able to develop this
application in about 15 minutes so let's
get started all right so to begin with
you need to have your Unity software
downloaded and installed so if you don't
have it already then you can visit this
website unity.com downloads and click on
download for Windows now this is going
to download the unity Hub software which
is going to look something like this and
it helps you manage all your projects
and it helps you manage the different
versions of editor that you have and for
each of the editor it will let you add
different modules that you need as per
your requirement so once you have the
unity Hub then you can scroll down so
you find the link for download archive
in the download archive you need to
click on download LTS releases and
that's because they don't have any bugs
and even if they are their updates that
Rectify them and the version that we're
going to use is going to be
2021.3.6 so make sure from the drop down
you select 2021.3 and scroll all the way
down till you find the version 6. now
make sure to download this and I'm
suggesting you to download the same
version as me and that's because if you
find any errors then it'll be easy for
me to help you guys fix it
now since I already have the editor it's
saying that I have it so let's skip that
part all right so once you have your
editor installed then you can click on
settings add modules and then you need
to make sure that you have these three
modules installed so the Android will
support with Android SDK ndk tools and
open jdk so you need to have these
installed and once that's done you can
go to projects and create a new project
we'll uh from the drop down if you have
different editor versions make sure
you're using
2021.3.6 we'll use the 3D core render
pipeline we'll name our project as
AR image tracking
image
tracking and click on create project all
right so we have a Unity project open
and the first thing that we need to do
is download all the packages and
resources that we'll be needing to
create this AR application so let's go
to Windows package manager and let's go
to Unity registry here search for AR
foundation so this is the one version
4.2.6 click on install
now along with this we need another
package which is going to be the AR core
so you can select the air core XR plugin
and click on install once again
foreign now let's go ahead and download
all the resources that we need to create
this application and the First Resource
that we need is an image that can be
detected so I'm using this particular
image from Game of Thrones and then once
the image is detected we need a model
that has to be spawned for that I'm
using this Dragon asset and finally once
you have your model spawned you should
be you should be able to move it around
as well and to do that I'm using the
joystick pack asset now I'll leave a
link for all these three in the
description below so you can also
download the same all right so now that
we have all the assets let's go ahead
and import them into Unity so for that
we'll go to Windows package manager and
in here let's search for the dragon
asset click on import
next we'll go ahead and import the
joystick pack as well
and finally let's go ahead and import
the image
there we go
so now it's time to set up our project
so let's go to file build settings and
the first thing to do here is to switch
to Android platform
so once that's done you can click on
player settings and in the other
settings make sure you uncheck
autographics API select the welcome API
and let's go ahead and remove that we
need to uncheck multi-thread rendering
and we'll scroll down make sure this is
level 24.
and here we need to change the scripting
back end from mono to Il to CPP and here
we got to make sure to check the arm 64.
so these are the settings that you need
to do in order to make sure that it runs
on your Android device next we need to
click on the AI plugin management make
sure you're on the Android tab and in
here check the AR core
all right so with that we have set up
our project now let's go ahead and set
up ours now creating the scene is fairly
simple first thing to do here is to get
rid of the main camera and then right
click select XR select air session
origin now this game object comes along
with ar camera and that's the reason why
we got it of the main camera and then
there's another game object that we need
to add so to do that right click select
XR once again and add AR session so once
you have these two we'll select the AR
session origin and add the component AR
tracked image manager now this component
basically uh tracks the image and once
it's done it instantiates this prefab
that we give but we're not going to do
it that way we're just going to give it
an image and then we'll write a separate
script which will spawn the prefab once
the image is detected so first thing to
do here is to create the serialized
library and image Library so we'll right
click in the project window click on
create go to XR and we'll select the
image reference image Library
and you can rename it if you like to but
I'm going to leave it as it is I'll
click on ADD image and let's add the
image that we have imported here
then select the air session origin and
drag and drop the image reference
library here next add a component we'll
create a new script we'll call this as
image Creator not image Creator we call
it as prefab Creator so
prefab creator
there we go
all right so here we are in visual
Studios let's go ahead and get rid of
this code over here and let's add the
package that we'll be using so it's
going to be using Unity engine
Dot XR
dot AR Foundation
all right now let's declare all the
variables that we need for the script
the first one is going to be a
serialized field
private
it's going to be of type game object and
it's going to be the dragon prefab
dragon
prefab
and next we need a vector 3 so let's
make it our serialized field once again
private
Vector 3 and let's call it as prefab
offset
now I'll tell you why we need this once
we go back into Unity but let's just
continue in visual Studios for now
next let's declare another variable
which is going to be a private game
object of and it's going to be called as
dragon and this variable is basically
going to store the instantiated prefab
and finally we need a variable to store
the Air Track image manager component so
it's going to be ar
tracked image manager we'll call it as
Air Track image manager there we go now
on enable so when it is enabled the
first thing that we need to do is go
ahead and get the aircraft image manager
component so we'll assign it to this
variable air attack image manager it's
going to be equal to gameobject dot get
component
KR tract
image manager
there we go and then let's subscribe to
its event on image changed when the
attack image is changed so it's going to
be ar
attract image manager dot track images
changed plus equal to on image
on image changed and all you need to do
is right click on this and go to Quick
actions and generate a method so it's
going to generate a method for us
automatically it's going to be of
parameter AR track images change event
arcs I know that's long but it's the
parameter that's there and it's going to
have an OBG as the output that we get
let's go ahead and get rid of this now
in here we want to have for each so for
each AR tracked image so for each of the
tracked image let's go ahead and rename
this as image in obj
in this particular obj that we get Dot
now when it is added for the first time
okay so for each of the image inside
this objection is added for the first
time what we want to do is we want to
instantiate the dragon prefab so and
then store it inside the dragon variable
as well so we're going to say it as
dragon
is going to be equal to instantiate
the dragon prefab and in which location
do we want it it should be above the
image so we're going to call it as image
dot transform there we go and then for
some reason of course some it could be
possible that any model that you're
using might have some offset so in order
to accommodate that we're going to call
it we're gonna use Dragon dot transform
dot position plus equal to the offset
value that we have
there we go and that that's and that's
about it so let's go ahead and save this
go back to Unity
and let's wait for the script to load
all right here we need to provide a
dragon prefab so let's go ahead and make
use of one of these Dragon prefab that
we already have so we'll go in here
we'll go to prefabs and I'm going to use
the terror Binger and use the blue one
so here you can see it's actually quite
big and just to give you a reference
we'll go ahead and create a cube of a
meter size print at zero so you can see
how big this dragon is so we need to
reduce its scale so I'm going to reduce
it to 0.015
0.015 and 0.015 there we go
now this cube is one one meter so for
example if I wanted to be something like
10 centimeter then this is how big is
going to be let's reset its position so
there we go so I think this is a good
size to have but you can vary the size
as per your requirement let's get rid of
the cube here now this blue dragon uh
will set this rotation to zero as well
but if you see the AR camera right it's
pointing in this particular direction so
which means that when this object spawns
it's going to look away from the camera
so to so to change that we'll have this
y as 180
next this prefab also has a animator in
place so let's go ahead and open that
now here you can see there are so many
animations that are there we don't want
all of them so let's go ahead and get
rid of these get rid of these now all we
need is take off and fly forward so
let's go ahead and get rid of these and
this and this as well perfect now let's
make a transition to here and from here
to here so now if I go to scene and
press play you can see that the dragon
is just going to take off and then it's
just gonna fly around in the same
position
perfect so we have our prefab ready
let's go ahead and add that so we'll go
back to here prefabs and here now before
you get delete this particular one make
sure to go to override and say apply all
let's click on blue and make sure it's
added so here you can see that the
position and rotation is still the same
so we'll make this 0 we'll make this as
180. perfect now we can get rid of this
select the AR system origin drag and
drop the blue prefab inside the dragon
prefab now talking about the offset so
if I bring this back here and if I press
play you can see that the dragon will
start flying now when it flies
and there's some offset and also even
here the base there's some offset to its
actual Center that's the reason why we
have offset here so you can leave it at
zero but um it's based on trial and
testing so I felt the best one would be
0.1 actually so this is the offset that
I like so I'm going to get rid of this
here again
and that's pretty much it now there is
one more script that we need so
basically we want to be able to move the
dragon around once it's spawned so to do
that we'll select the dragon We'll add a
component we'll create a new script
we'll call it as
Dragon controller
and let's open this
yeah and so let's open this and I'll see
you in digital Studio all right so here
we are in visual Studios let's go ahead
and get rid of this code over here now
the first thing that we need is our
variable to store the speed so it's
going to be serialized feed private load
and we'll call it as speed and then we
need uh two more variables our first
variable is going to store the fixed
joystick component and the second one is
for the rigid body so let's go ahead and
create a private
fixed joystick here and we'll call it as
fixed joystick and let's create another
variable for the rigid body component
there we go we call it as rigid poly now
on enable so when it is enabled we want
to get this particular component right
away and so the rigid body as well I'm
going to change this name I'm going to
make the B capital there we go so fixed
rigid uh so fixed joystick is going to
be equal to
find object of type where we want to be
fixed joystick there we go so we have
that component and we also need the
digital body component so rigid body is
going to be equal to game object Dot
get component
and let's get the rigid body component
all right so once we have this in the
fixed update so fixed update we want to
move this right so to move it around
first thing that we need to do is get
the joysticks X and Y values so we'll
have it as float
float X well is going to be equal to
the fixed joystick dot horizontal axis
and the next one is going to be float
y value is going to be equal to fixed
joystick dot vertical all right once we
have this then we can Define as to which
way it has to be moving so first we'll
have the moment which is going to be a
vector 3 so Vector 3
movement
is going to be equal to
new
Vector 3 x well
comma 0 we don't want the dragon to move
up and down and then we'll finally say
y1 so here we are converting the 2D
access into moment along the x and z
plane all right so once we have the
moment we can make it move in that
particular direction for that we'll make
use of the Velocity uh property of rigid
body component so we'll say rigidbody
dot velocity is going to be equal to the
moment times the speed
perfect so now at this particular stage
Your Dragon will be moving but it will
not face the direction in which it has
to move so in order to do that we'll say
if the X Val is not equal to
0 and
the Y valve is also not equal to zero so
only in this case we want to say
transform dot Euler angle is going to be
equal to Nu
Vector 3 and here it's going to be
the uh transform
is going to be transform dot Euler angle
dot X now if you think about it we want
the dragon to rotate around the y-axis
so which means that the rotation about x
and z axis remains constant and does not
change so we'll say transform dot Euler
angles at X comma so for y we will use
the math function so math f
matter dot 8 and 2 and in here we'll
pass in the X valve comma y Val
there we go I think I'll scroll this
slightly up here so that we can see as
well and zoom out a bit okay so and then
multiply this by math F dot gradient to
degree and finally we'll take transform
dot Euler angles dot Z
yeah there we go so that's about it
semicolon
perfect so now with this script you
should be able to move the player along
so let's save it and go back to Unity
all right so now let's add the joystick
to our scene to do that you'll have to
right click select UI select canvas next
scroll down in the canvas scalar we'll
change it from constant pixel size to
scale uh scale with screen size and
let's change this value so I think the
best values to take would be something
like this one so it's going to be
2160 cross 1080 so this is like almost
the standard size of all the modern
smartphones that we have and then let's
go to joystick pack prefabs then here we
have the fixed joystick drag and drop it
inside the canvas now you're able to see
the joystick here so let's double click
on it and I'm going to increase the
scale to 2 so that is bigger and easy to
use and probably more slightly above and
towards the right here
yeah I think so much is fine the low
prefab has a size of 0.5 we have edited
its uh animation and here we need to add
two more components the first one is a
rigid body make sure to uncheck use
gravity and the next one is the dragon
controller and here we'll set the speed
to 0.5 and then let's go up here click
on overrides and say apply all so that
it gets applied to the prefab and let's
go ahead and remove this so that's about
it let's save the scene and let's now
build it onto our device so to do that
you will have to go to file build
settings and then before you actually
build it you need to connect your device
to your laptop or to your PC so let's go
ahead and do that all right so I've
connected it you need to enable USB
debugging mode so if you're not sure how
that's done then I'll leave a link for
that over here or in the description so
you need to enable USB debugging so once
that's done you'll let's refresh here
and here you can be able to see your
device minus one plus and then we'll say
click on build and run we'll right click
create a new folder we'll call it as
builds
we'll call it as bills there we go
let's open it we'll call it as test
Maybe
foreign
and it's going to take a while and I
will see you once it's done building
all right so here we have the
application running let's go ahead and
scan the image and once we have the
image scan we get the dragon prefab and
now we can use the joystick to move it
around
it's super cool and it's so much fun
all right so this was a video to show
you how quickly you can develop an AR
application and you learned about image
tracking now if you want to learn in
depth and learn more about the
foundation and its features then you
should definitely check out this
playlist over here wherein I talk in
detail about each of the component and
how phase tracking works and
are all the different things related to
AI Foundation all right I hope you
enjoyed this video if you feel that you
have learned something new then I'd
highly appreciate it if you can leave a
like And subscribe and as usual I will
see you in the next one
Weitere ähnliche Videos ansehen
AR Indoor Navigation from scratch in under 30 minutes with Unity 6
Learn C# Scripting for Unity in 15 Minutes (2024 Working)
Monitoring Suhu Dan Kelembaban Menggunakan ESP32 + DHT22 Dengan Protokol MQTT
Cara Install React Native + Full Setup [2024]
Govee H6003 WiFi LED Bulb User Manual | Installation Guide and Setup
Robotic Arm with Arduino - Save/Play/Export/Import Positions.
5.0 / 5 (0 votes)