crowd system

Are you making an open-world game? How about an RPG?
Have you been thinking about including a crowd AI that aimlessly walks around your streets?

How about if I told you that you could do this easily - Without having to set up a Behaviour Tree? That's right!

It's all possible and I'm going to tell you just how to achieve this effect.

----------------

Before we begin, we're going to need a number of things:

  • X amount of Characters using the same Skeleton
  • A Walk Animation for these Skeletons



NOTE: If you're worried already and you're thinking "How the heck would I create an animation for all these skeletons. Heck, I can't be bothered to create all these characters! Fret not, Head over to Autodesk's Character Generator. It's free, and you can create as many crowd people as you want - And as long as you import it to UE4 correctly, you can get them all to use the same UE4 skeleton, Regardless of height / weight!

Once I generated around 8 characters, I simply opened up Motionbuilder, imported the default walk cycle (In the MotionBuilder Previs folder!), saved it out and applied it to the UE4 Skeleton that the import had created. Now ALL the characters I created had a walk animation!

-----------------------

Step #1  - Import your Character (With the first character, Don't select anything for the Skeleton and for the rest of the imported characters, assign them to the skeleton you created with the first character!

Step #2  - Create a new Blueprint > Set it as Character and called it AICharacter

Step #3  - Open this up and in the mesh part in Component, where it asks for a Mesh, put any of the characters.

Name:  3.jpgViews: 5770Size:  313.8 KB

Step #4  - Go to the event graph, and in the tabs just above the blueprint, click Construction Blueprint.

Step #5  - Create a Random Int node and where it says "Max", type in however many characters you have.

Step #6  - Now create a Switch on Int node and create as many pins as the Random Int has (For example, if you put Random Int Max = 5, put 6 pins .etc)

Step #7  - In your Compact Blueprint Library (Which you get by right-clicking), type "Get Mesh".

Step #8  - From the empty pin of "Get Mesh", create "Set Skeletal Mesh". Do this as many times as you need (If you have 5 characters, do this 5 times).

Step #9  - Hook each "Set Skeletal Mesh" to the empty slots of the "Switch on Int" node.

Name:  1.jpgViews: 5708Size:  262.7 KB

Step #10  - Now head into the "EventGraph":

Step #11  - Event Begin Play > Get All Actors of Class > Set the Actors in this Node to "Target Point" > (From "Out Actors") Promote to Variable.

Name:  2.jpgViews: 5798Size:  119.3 KB

Step #12  - Create an Event Tick and connect a Branch to this.

Step #13  - Right click and "Get Character Movement".

Step #14  - From the pin of "Character Movement", get "Velocity".

Step #15  - Now create a "Get Vector Length" node and connect the Velocity.

Step #16  - Create a "Float >=" node and connect this to the branch.

Name:  4.pngViews: 5649Size:  56.0 KB

Basically what we did is ask the Blueprint, Are we moving?

Step #17  - Create a "Get Controller" node by right clicking

Step #18  - From the pin of Get Controller, create a Simple Move To Actor node (And connect this to the "False" of the Branch).

Name:  5.jpgViews: 5665Size:  90.2 KB

Step #19  - Drag in your Variable you created from "Get Actors from Class" and select "Get".

Step #20  - From your Variable's Node, create a "Array Length" node and from that create another "Random Int" node.

Step #21  - From your "Random Int" node, create a "Get (Array)" node and plug in your Variable again here.

Step #22  - Connect this to the "Goal" of Simple Move To Actor!

Name:  6.jpgViews: 5668Size:  152.3 KB

Basically this whole blueprint converted into English goes like:
When the game starts, find all the Target Points and remember them. Now every second, see if we're moving. If we're ARE do nothing, if we are not moving, then from all the target points, pick a random one and walk towards it!

We're almost done. All we have to do now? Five super-simple things!

1. Create an Animation Blueprint for the Skeleton (I'll leave that one up to you, there's so many tutorials about it!)

2. Create a bunch of Target Points in your Scene by going to the "Modes" box in the top-left of Unreal Engine, and in the search field and put "Target Point". Then drag a boat-load and whack them in random areas of your map.

3. Create a NavMesh Bounds Volume (Search the "Modes" box again if you need to!) [You only need one!]. Make sure it covers where you want your crowd to move around in!

4. Wait till the Navmesh has finished building (Re-build you map just be safe!)

5. Drag a boatload of the Character BP you created all over the map.

----------------------

And that's it! You've got loads of different people walking around as if they're super-busy!

That's all folks!

You did it, Good job! Now expand on this super-simple tutorial and create some super-awesome stuff!

Edit: For those curious, here's what you'll end up with thanks to this Super-Simple Tut!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值