top of page
搜尋
作家相片Liling Liu

[Chaos Physics] Unreal Engine 5.2 物理約束可掛接拖車車輛教學 |Physics Constraint Hitchable Trailer


物理約束可掛接拖車車輛




在這邊使用 Driving Chaos Vehicle 專案來製作掛接拖車

 

匯入模型和貼圖: Crab the model and texture into Browser






拖車已經有綁訂了

 

FBX import Options:

Skeletal Mesh: turn on

 

Combine Meshes: If you have many separate mesh, you could turn on














Plugins:

 

ChaosVehiclesPlugin



WheeledVehiclePawn

 

Create BP:

 

Right click mouse > Blueprint Class

 

All Classes:

search: vehicle

Select “ WheeledVehiclePawn ”




Mesh >  Skeletal Mesh Asset > trailer




Wheel Setup

 

選擇  Vehicle Movement Component

 

這個拖車有兩個輪子,所以按兩次+ 增加

 

Wheel Setup > Wheel Setups > +  



到骨頭檔案並複製骨頭名字

 

選上骨頭 > 右鍵 > Copy selected Bone Names

 

 

 

 Paste to Wheel setups index bone name


Turn on Simulate Physics



Trailer Physic 拖車物理

 

Open physics Asset


Select physic and delete

 

因為預設的物理形狀不符合拖車



Select wheel bones > Primitive shape: Sphere >Add bodies



Select Root bone > Primitive shape: Single convex Hull >Add bodies



Input Action

 

Project settings



Go to Engine - Input


Action Mappings: Interact--> T



Animaton

 

Obtain the behaviors we want for our vehicle.

 

Select trailer skeleton > right click mouse > Create > Anim Blueprint



Opne AnimBP > Class Settings > class options > Parent Class : Vehicle Animation Instance

 

 

Mesh Space Ref Pose: this is used to return the mesh space reference pose for our skeletal mesh in the Animation Blueprint

 

Wheel Controller : offloading a lot of the work in creating these types of animations, you can use the Wheel Controller Node to drive the animations.



GO to BP_trailer

 

Select Mesh > Animation > Anim Class : ABP_trailer



準備互動物件

 

Open BP_CAR

 

增加碰撞體 ,命名為 Docking.




Blueprint > Blueprint Interface

 

藍圖介面是一個或多個函數的集合 - 僅名稱,無實作 - 可以新增到其他藍圖。 這本質上就像一般程式設計中介面的概念,它允許多種不同類型的物件透過一個公共介面共享和存取。



Functions: Interact

Inputs: car (BP_Car, object reference)



Open BP_car

 

Use for loop to check does implement interface, if true, does interact


Opne BP_Trailer

 

Add Collision

 

Naming: Trigger_coli


Add PhysicsConstraint

 

物理約束是一個關節,可讓您將兩個 Actor 或組件連接在一起,並對它們施加限製或力。



Constraint

Conponent name 1: Mesh

Conponent name 2: Trigger_coli

 


Control Physics constraint - Angular Limits

 

Swing 1 motion  (Z) : Limited, swing 1 limted: 60

Swing 2 motion (x): Locked

Twist motion (y): Locked


Add Text Render




1. Text: type the information.

2.Turn off visibility


Add cube

 

In order to let trailer to stand on the ground, so add cube


Add Interface

 

Class Settings > Implemented Interfaces > select BI_Interact



Add variables:

1. CanHitch :Boolean

2. TryHitch : Boolean

 

Select trigger_collision box add begin overlap and end overlap

 

When End overlap,  try Hitch: turn off, and text does not show


When begin overlap,  try Hitch: turn on

 


Get  car docking and trailer trigger_coli’s world location and do float to integrate value

Does car docking X subtract trailer trigger X to get the value. The value is less equal what we want the value. However, we might be get the negative value, so here I use ABS to get positive value.

 

Does car docking Y subtract trailer trigger Y to get the value. The value is less equal what we want the value.

 

X and Y value both are true and return true.

Set true/false to can Hitch


Set text visibility and delay the time.

After completed, try hitch again to condition, if true, cast to bp_Car



Interact Event

 

如果可以掛接,則汽車連接到拖車且移動並設置約束組件。 關閉嘗試掛鉤並設定文字可見性。

 

否則,當再次按下T時,釋放油門並打破約束,並設定嘗試掛接:打開



Result:



Stand

 

當汽車連接到拖車時,支架就會消失。

 

 

Creat function: RemoveStand

Add Variables: StandRemovedBool :bool

Open RemoveStand function:

Destory stand compoent, and set standRemovedBool: on, and call stand removed


Event Dispatchers: StandRemoved


Event graph

 

Using event tick to do event StandRemoved.

如果支架有效,請移除支架。 如果沒有,則執行一次列印字串



Event Interact:

Remove stand event and turn off standRemovedbool

 


Result:






Youtube Tutorial:






Plugins: ChaosVehiclesPlugin

 

 

Sketchfab  -  Car Scene:

 

Sketchfab  - Generator Trailer:

 

 

Physics Constraint Component:

 

 

 

How to Set up Vehicles Unreal Engine 5.0

 

Ref: Unreal Engine Truck Tutorial: Trailer System



教學專案和文件下載 /  Full Project and Document Download:

 

 

  

贊助 / Support Me

 

 

 















17 次查看0 則留言

Comments


bottom of page