Unreal Engine 5 - AI Driven Cars
Summary
TLDRこのビデオでは、AIが運転する車を実装する方法が解説されています。車はスプラインに沿って自動的に進むようにプログラムされています。車は人間のプレイヤーのように、加速度とステアリングを使用しますが、加速度とステアリングの量はコードによって決定されます。スプラインを使用して軌道に沿って車を動かす方法を学びます。目標は、車が与えられた速度で軌道に沿って自動的に進むことです。スプラインのポイントをブループリントから取得する方法がないため、新しいフォルダを作成し、アクタークラスを追加します。車のブループリントを作成し、スプラインを参照する変数を追加します。車が前進するように制御し、最大速度を設定します。次に、車が曲がる方法を決定します。車のステアリングを制御するために、車には左と右の2つの参照ポイントがあります。これらのポイントを使用して、車が右ターン、左ターン、またはステアリングを行うべきかどうかを判断します。最後に、車がスプラインの終点に達したときにループを続ける方法を学びます。デモンストレーションでは、車がスプラインに沿って滑走路を顺利完成し、繰り返しループが可能です。
Takeaways
- 🚗 自動運転車の実装について解説しています。車はスプラインに沿って動くだけでなく、加速度やステアリングをコードで決定します。
- 📂 プロジェクトを作成する際には、スターターコンテンツは必要ありません。独自のフォルダとプロジェクト名を設定しましょう。
- 🔄 スプラインを使用する際には、ランスケープスプラインアクターからブループリントにポイントを取得する方法が必要です。
- 🛣️ スプラインの形状を調整する際には、ALTキーを押しながらポイントを動かすことで、ポイントを複製できます。
- 🚦 スプラインに沿って車の進行方向を決定するために、左ポイント(LP)と右ポイント(RP)を設定します。
- 📏 ターゲット地点までの距離を計算し、車が右か左に曲がるべきかを判断します。
- 🚦 スプラインの長さを超えた場合、ループさせて車が継続的に進むように設定します。
- 🏎️ 車の速度を制御するために、最大速度を設定し、速度がその値を下回る場合にのみ加速させます。
- 🔧 車がスプラインに沿って滑らかに進むように、ステアリングの調整を行います。
- 🔄 車がスプラインの端に到達した際に、スプラインの長さをゼロに戻してループを続けます。
- 📉 車が曲がる角度を滑らかにするために、ステアリングの変化率をフレームレートから独立させます。
- 🔗 プロジェクトファイルはPatreonページでダウンロード可能で、サポートが必要な場合はPatreonクライバーシップを検討できます。
Q & A
AIが運転する車はどのようにして軌道に沿って運転するようになりますか?
-AIが運転する車は、コードを通じて加速度とステアリングを決定し、車両モーメントコンポーネントを使用して運転します。これは人間プレイヤーと同様ですが、加速度の量とステアリングはコードによって決定されます。
スプラインを使用して車をどのように制御しますか?
-スプラインを使用する場合、スプラインポイントからブループリントにポイントを取得する方法が分からないため、新しいフォルダを作成し、アクタークラスを追加して、デフォルトで2つのポイントを持つようにします。
AIが運転する車の速度をどのように制御しますか?
-車の速度を制御するために、車の前進速度を取得し、設定した最大速度値(例: 40km/h)以下であれば加速を適用するようにします。
AIが運転する車が壁にぶつからないようにするにはどうすればよいですか?
-車が壁にぶつかないように、車にセンサーのようなコンポーネントを追加し、スプラインから得られるポイントと比較して、左または右にステアリングするかどうかを決定します。
AIが運転する車がスプラインに沿って滑走路を続けるためには何が必要ですか?
-スプラインの長さを超えた場合、スプライン距離をリセットしてゼロに戻す必要があります。これにより、車がループ内で継続的に滑走路を続けることができます。
AIが運転する車が曲がる方向をどのように決定しますか?
-AIが運転する車が曲がる方向を決定するために、スプラインから得られるポイントと車の参照ポイントとの距離を計算し、どちらが近いかに基づいて左または右に曲がる方向を決定します。
車が揺れ動くのを防ぐためには何をしますか?
-車が揺れ動くのを防ぐために、ステアリング量を徐々に変更するようにします。これは、ターゲット量から現在値への変更を、デルタ秒数と一定の乗数(例: 40)で乗算することで実現します。
AIが運転する車の速度を上げるにはどうすればよいですか?
-AIが運転する車の速度を上げるには、最大速度の設定値を上げる(例: 50km/h)ことで、車がより速く運転できるようになります。
プロジェクトファイルはどこでダウンロードできますか?
-プロジェクトファイルは、Patreonページからダウンロードできます。Patreonページのリンクは説明欄に記載されています。
AIが運転する車の開発に興味を持ってくださった方々はどのようにサポートできますか?
-AIが運転する車の開発に興味を持ってくださった方々は、Patreonクラブのメンバーシップを取得してサポートすることができます。
AIが運転する車の開発で使用された主要な技術は何ですか?
-AIが運転する車の開発で使用された主要な技術には、車両モーメントコンポーネント、スプラインを使用した経路制御、加速度とステアリングのコードによる決定、およびループでの連続運転のためのスプライン距離のリセットが含まれます。
AIが運転する車の開発で直面した最大の課題は何でしたか?
-AIが運転する車の開発で直面した最大の課題は、車がスプラインに沿って滑走路を続ける方法、特に曲がり角の処理と車が揺れ動かないようにすることです。
Outlines
🚗 AI駆動車の実装方法
AI駆動車の実装方法について説明しています。車はコードによって運転され、加速度やステアリングを人間のように使用しますが、加速度の量やステアリングはコードで決定されます。ゲームと車両テンプレートを選択し、プロジェクトを作成します。目標は、車がスプラインに沿って自動的に進むようにすることです。スプラインを使用する際のポイントの取得方法についても説明しています。
🔄 車両ブループリントのカスタマイズ
車両のブループリントをカスタマイズし、AIが車を自動運転させる方法について説明しています。スプラインに沿って車を動かすために、スプラインポイントを複製する方法や、角度スナップを無効にする方法を紹介しています。また、車両ブループリントで子ブループリントを作成し、スプラインを参照する変数を追加する方法も説明されています。
🚦 加速と速度制御
AIが車を自動運転させる際の加速と速度制御について説明しています。車を前進させるために、加速のカスタムイベントを追加し、最大速度を設定する方法を説明しています。車が壁にぶつかないように、速度を40km/h以下に制御する方法についても紹介されています。
🔍 スプラインの参照と進捗の確認
スプラインの参照を取得し、AIがスプラインに沿って進むように制御する方法について説明しています。スプラインの各ポイントの位置を取得し、車が目標地点に到達するまでの距離を計算する方法を紹介しています。また、車がスプラインの進捗状況を確認する方法も説明されています。
🛣️ ステアリングの制御
AIが車を自動運転させる際のステアリング制御について説明しています。車にセンサーとして機能する参照ポイントを追加し、スプライン上のポイントの位置を取得して、車が右または左に曲がるべきかどうかを判断する方法を紹介しています。また、車がスプラインに沿って滑らかに進むように、ステアリングの調整方法も説明されています。
🔁 ループでの動作確認
スプラインの最後で車の動作を確認し、ループで動作するように設定する方法について説明しています。スプラインの長さを超えた場合に、スプラインの距離をリセットしてループを続ける方法を紹介しています。また、車がスプラインに沿って滑らかに進むように、ステアリングの調整と速度の制御方法も説明されています。
🏁 完成とプロジェクトファイルの提供
AIが車を自動運転させるプロセスが完了し、プロジェクトファイルが提供されることについて説明しています。車がスプラインに沿って滑らかに進む最終デモンストレーションを行い、車速度を50km/hに設定して2周続けて動作を確認しています。また、プロジェクトファイルはPatreonページからダウンロードできると発表しています。
Mindmap
Keywords
💡AI駆動車
💡スプライン
💡ブループリント
💡加速度
💡ステアリング
💡車両運動コンポーネント
💡カスタムイベント
💡参照ポイント
💡距離計算
💡ループ
💡パトロンページ
Highlights
Introduction of AI-driven cars that mimic human driving behavior through code.
Use of vehicle moment components such as acceleration and steering in AI cars.
Decision-making for acceleration and steering is coded, not manual.
Selection of games and vehicle template to start the project without starter content.
Creating a folder named 'vehicles' for organizing project files.
AI car's path-following is achieved by adhering to a spline.
Landscape spline actors are used, but extracting points for blueprints is challenging.
Quick tip: Holding 'Alt' while moving spline points allows for duplication.
Disabling angle snapping to move spline points freely.
Creating an actor class 'BP_Road' with two spline points as a starting point.
Implementation of a child blueprint for the vehicle with a variable of type 'BP_Road'.
Introduction of custom events 'accelerate' and 'turn' for autonomous driving.
Defining a maximum speed for the AI car to prevent collisions.
Using vehicle movement component to get forward speed and control acceleration.
Employing a selection mechanism to apply acceleration based on current speed.
Incorporating a loop for the AI car to continuously follow the spline path.
Utilizing reference points (left and right points) for detecting steering direction.
Calculating the distance to target points on the spline for steering decisions.
Smoothing out steering with a lap and delta seconds for a more natural turn.
Adjusting the 'check gap' and 'distance in payment cap' for better corner handling.
Final demonstration of AI car driving at 50 km/h for two consecutive rounds without issues.
Project files and Patreon support information provided for further engagement.
Transcripts
hello everyone so today we are going to
implement this ai driven cars
as you can see here these cars are
driven by
through the code so
it's not like exactly they are just
moved through moved along a spline
these cars actually use the vehicle
moment components they use acceleration
and steering just like a human player
but instead the acceleration amounts and
the steering is decided through the code
so
yeah
let's see how to implement this system
today so these guys can just
continuously go through
this track
in a given speed continuously
okay so i'll select games and vehicle
template
and
i think i already have a
folder named vehicle
oh no okay
vehicles
and i'll name this
ai
cause
i don't need starter content so let's
create the project
right now this is what i have
um
let me play
okay so it is basically working
so
my goal is to
make the car
automatically drive
in this path
follow in a spline
so how can we do that
first
uh
these uh splines
but landscape spline actors so we don't
really have a
i don't really know a way to get points
from this into a blueprint
so
let's create a new folder
be
blueprints
and let's create an actor class
pp
root
right here
let's add
spline
and by default let's
have
two points
like this
compile
and
that should be the starting point
let's see here
yeah this is
also the player start
so let's put
where is it
bp road here
hmm right
now let me make this road
match this road
so by the way if you keep alt pressed
and move one of these spline points you
can duplicate it
quick tip if you don't already know that
let me disable angle snapping
so i can
move it freely
i don't need to have an exact
map
for this plane into the
into this
road underneath just a rough one or two
but anyway i try to make it match
as
best as possible
as close as possible
okay
[Music]
right
so this is this line
and
it starts
from here and ends from here
now
where is the vehicle blueprint
here here i'll create
a child blueprint
hey
and place one here
and
now
open the icar
and
here
i'll add
a variable
what
this should be from the type bp
rod
i'll make
this instance irritable so we can assign
this in
here
pp road
okay
now
here
uh
[Music]
in the tick
so
if i go to the parent
of the ai car
you can see user inputs
where is it
for throttle and
yeah this move forward
is connected to throttle and move right
is connected to steering so here i'll
add
a custom event
accelerate
and
[Music]
we need to float
input
just like this one
so
[Music]
and also we need to connect
execute
this same code so therefore
let's do something like this
let's convert this
to a macro
forward them
and duplicate
connect the same thing
into accelerate custom event
i'll just call it value
and similarly
uh
done
custom event
turn
i'll duplicate the same
piece of code
like this
now
we have these two
custom events that we can use to drive
the car
automatically through the blueprint so
here how
to find
right so
now we need to give these two inputs
turn
and accelerate so to give accelerate
without thinking about turning let's
just
make the car move forward
so if i call
[Music]
accelerate here
with
maybe 0.2
or just say 1
don't know
it should move forward
and now here let me simulate
without
playing see now the car goes forward
until it hit
the wall
so right
now how can we define a max speed
let's say
40
so we can
get the vehicle movement component
get forward speed
what kind of a value do we get here
actually we know that because
we can find that because if i
play the game you can see in the bottom
left
the speed
the car is pushing me
let me put
the player car behind
see it's
costs around 120
okay and the calculation is here in
vehicle player controller
speed
okay if mph we have to multiply by this
value
if
k and ph
this value
so let's consider only kmph
and if i want to
keep the speed under let's say 40
we can say
if
this is
less than
40
apply acceleration
now the car didn't go that fast
but still it bumps into
a wall
to test that
let's make the speed even further
let me promote this to variable
max
speed
yeah i speed
otherwise
it could be a bit
confusing
it's q5
so if i'm correct car should go really
slow
it doesn't look like going slow
why
let's print what we get here
oh
it says hello
oh sorry
two
let's forget about this multiplication
and put directly what we get here
oh
all right so actually uh when we you
have a user input we always call this
if we are not pressing
forward button with zero values so maybe
that's the case
also we need to consider
the absolute value
so here
instead of having a branch
we can
do a selection
if this condition is true one otherwise
zero
okay
it's not moving at all
let's try 40
with
this multiplication
right now it's moving
not that fast okay good
now we have a car that goes with some
control and the next step is
making it turn
and this is also not
i don't want it to be just some
following the spline or just moving the
car through the code along the spline
it's that's not the way i want i want
the ai to use the actual
vehicle movement component and drive the
car
right so how can we do that
[Music]
from the road
and the construction script
oh no here
let's convert this to a validated get
and get spline
promote this to variable
rod spline
and then
compile
now we should have a reference there
in the vein graph
so this is regarding acceleration
let's collapse
speed
control
then we need
a way to detect
steering
so
for that
uh
let's
have two
components here in the car
like sensors
and
[Music]
the mesh
same component
these are just
reference reference points
one is here
near the left field
i'll call it lp just left point
and
another one
duplicate
rb
right point
on the right side so that means plus 120
now
we have two reference points
uh
from the
spline
we have the spline
let's get
get
location
at distance
along along spline and i'm going to use
the workspace
so
as the distance let's promote this to a
variable
i'll name it target spline
distance
so this
variable represents
the
distance along the spline that the car
is trying to reach
and by using these
and these two points are defined i am
going to
determine
whether the car should have a right turn
a steering or a left steering
right let's see how this goes and we can
start from there
from what
that's from register variable
target point
now
the distance from the target point
to the call
location by collocation
[Music]
detector location
if the distance is less than
first we need to calculate distance
is less than let's say
500 meters
the branch
we need to
extend this distance
so let's add another 500
so that we can keep the car moving
forward
get the spline distance
add
ah let's promote this to variable
let's call it
check
cap
i don't have a better name for that
at the moment
and set it
as the target distance
new target distance
if the distance is
higher than the check gap this distance
if it is higher than the check gap
we don't have to do anything
one more thing
if
this exceeds
uh
the maximum length
of the
spline we need to reset it back to zero
so that
the we can make the car continue
in a loop
but let's look into that part later
for now let's just
see if the car can continue one round
now how to determine the distance uh the
direction
and we have can give steer
what's the function name i give
turn
um
shall we name this
tear
that seems
more appropriate
so how do we determine this value
as the first attempt
let's get the target point
and get these two points
get
word
location
of both points
[Music]
and calculate distance
to each point
then
if
lp is closer to that point
to the target point
we should turn left if rpa is closer
we should turn right
right
let's see if that works
i'm not 100 sure to be honest
uh
if this one is greater
than this one
that means l p is
that means rp is closer yeah
to select float
based on this
plus one minus one
maybe not
plus one like
0.2 let's try first
let's try
uh before that
let me remove that print
it's
overloading the screen
okay car is coming
and it should turn right
it is turning right but
not enough
okay
so then
let's try
0.6
the car is sort of
shaking
in two sides which
we should do something to avoid that
other than that it seems it can follow
the spline
let's see
yeah it can
and also
right let's prevent that
shaking to the sides
maybe we can prevent it if i
consider
[Music]
the difference amount
let's say
if this value is
let's set the multiply here
and select the multiplier
based on this difference
if the difference is let's say
let's promote this to a variable
get difference
10.
so if the difference is less than 10
it's not done
until it goes higher than 10
if it is
less than if it is higher than 10
let's turn
now it's not shaky
still not perfect
all right
maybe
okay
there is a way to
prevent this
so let's promote
this
steering into a variable
here
amount
instead of directly setting it
let's do a lap
use it like this
get this dear amount initially it will
be zero
left
to whatever is target amount
with the
we do have the delta seconds here
so
still delta seconds
multiplied by i don't know
40
by the way i'm multiplying with delta
seconds to keep this change rate
con
independent from the frame rate
it seems working
yeah much smoother than before
but it's still not good
and let's see what happens when it
reaches the end
one more thing well when it reached the
end
we should do this
let's collapse this
set spline
distance
if
this value
is greater than
get the road spline
length
we can do a selection here
if it is greater than
the this
target display and distance should be
zero otherwise this value
so car would be able to continuously
follow
and also maybe
here
instead of
increasing
oh no not there here
check gap
this is 500 if i reduce that i think
ah not
check gap
here
check gap here is fine
but uh
for here instead of check gap
let's introduce a new variable
distance in
payment
cap
let's say 50.
okay
and
yeah
let's try decreasing this a bit
where is the bar
so when you reduce that
it can't get tight corners but for this
map it works fine
oh not
no
that's not a good idea
so let me
change it back to
0.6
and let's have focus
let's wait till they
complete one round
to check if they can
continue in a loop
yeah it seems they can continue in a
loop without an issue
all right
so with that i'm going to
finish this episode so yeah you can see
the final demonstration
so here i have slightly increased the
car speed to 50 kilometers per
hour
rather than 40
and this is after coin two consecutive
rounds
all right so thanks for watching as
always project files will be available
here for the download
in the patreon page link would be in the
description below and if you like to
support my work
you can get the membership of the
patreon club see you in another episode
goodbye
Browse More Related Video
![](https://i.ytimg.com/vi/xDqP7hGGJEw/hq720.jpg)
PHOTOREAL CAR RENDER TIPS | Unreal Engine 5
![](https://i.ytimg.com/vi/znEsOTkHbIA/hq720.jpg)
CAR ANIMATION USING SPLINE | Unreal Engine 5
![](https://i.ytimg.com/vi/sHhzNsKnF4E/hq720.jpg)
Lakewood Police offers auto theft prevention program for residents
![](https://i.ytimg.com/vi/UcBAFWAtvVs/hq720.jpg)
Visual scripting in CT.JS -introduction
![](https://i.ytimg.com/vi/chmjD_lI3Jc/hqdefault.jpg?sqp=-oaymwExCJADEOABSFryq4qpAyMIARUAAIhCGAHwAQH4Af4EgALgA4oCDAgAEAEYUCBlKC0wDw==&rs=AOn4CLDvaMfG-4mKpAOCLs3gONpW6TpGcQ)
How Fast Does My Car Lose Its Value?
![](https://i.ytimg.com/vi/h1d2x4gFREY/hq720.jpg)
From fuel to electric: European auto industry faces 2035 deadline • FRANCE 24 English
5.0 / 5 (0 votes)