Difference between revisions of "Creating a New Creature AI"

From RPG Creation Kit
Jump to navigation Jump to search
Line 3: Line 3:
The Creature AI allows you to quickly setup any animated 3D model  to be a AI Entity in the RPG Creation Kit, as opposed as the RckAI which requires you to setup a new Race and have your 3D models in a determined way.
The Creature AI allows you to quickly setup any animated 3D model  to be a AI Entity in the RPG Creation Kit, as opposed as the RckAI which requires you to setup a new Race and have your 3D models in a determined way.


In this tutorial, we are going to create the Skeleton featured in the Update video, a Skeleton made by ''IronicGame'' you can download for free [https://assetstore.unity.com/packages/3d/characters/humanoids/fantasy/rpg-skeleton-35463 on the Asset Store].
In this tutorial, we are going to create the Skeleton featured in the Update video, made by ''IronicGame'' that you can download for free [https://assetstore.unity.com/packages/3d/characters/humanoids/fantasy/rpg-skeleton-35463 on the Asset Store].


This model, other than being super cool, comes also with even cooler animations - I suggest you download that asset and follow along with it during this tutorial, then you'll be able to setup any other 3D Model you want.  
This model, other than being super cool, comes also with even cooler animations - I suggest you download that asset and follow along with it during this tutorial, then you'll be able to setup any other 3D Model you want.  
Line 75: Line 75:
While the others can remain blank. Refer to the Image on the right:
While the others can remain blank. Refer to the Image on the right:


Next-up, if you want your Creature to die with a Ragdoll, add a "'''Ragdoll"''' Component and leave it for now, we will come back to it later.  
Next-up, add a "'''Ragdoll"''' Component and leave it for now, we will come back to it later. (Add it even if you're not going to use Ragdoll)


Finally add an "'''AI Sounds'''" Component and insert the AudioClips you wish for your Creature's sounds.
Finally add an "'''AI Sounds'''" Component and insert the AudioClips you wish for your Creature's sounds.


Now it is time to create the Ragdoll, and we can do that with the Unity built in tool. Click in the top-bar on "GameObject->3D Object->Ragdoll and configure the window by inserting the correct bones of the Armature:


[[File:CANC 7.png|440x440px]]


And click on '''Create'''.
Now if you're going to use the Ragdoll, now it's the time to come back at it. Look at the "SKELETON" GameObject, in the Inspector, and Right Click on the "Ragdoll Script", then select "Find Rigidbodies". That will fill the Rigidbody Array with the rigidbodies we've just created.
[[File:CANC 8.png|291x291px]]
Great, now we have to designate those Rigidbodies to be the '''Body Parts''' of the Creature, that will make it hittable.
Select in the Hierarchy all the GameObjects we've put in the Ragdoll Window before and do the following:
# '''Change their Tag to be RPG Creation Kit/BodyPart'''
# '''Change their Layer to be BodyPart, and make sure to click "No, this object only" when asked to set the layer for all child.'''
# '''Add Component "BodyPart".'''
We have almost finished, now go through every GameObject and select the correct "This Body Part" in the "'''BodyPart'''" Component. You may want for the "Bip01 Pelvis" to select "'''Chest'''", for the "Bip01 LThigh/Calf" to be "'''Leg"''', and so on. What this does, is to designate the parts used for Locational Damage.
It is time to add the '''Looting Point.''' Add an Empty GameObject to "Bip01 Pelvis" (which is the Hip bone of the Skeleton), name it "LootingPoint" and do the following:
# '''Add a Capsule Collider Component and scale it accordingly to Creature's Size. Then make sure to set it as a Disabled Component.'''
# '''Add a Rigidbody Component and uncheck "Use Gravity", "IsKinematic" must be checked.'''
# '''Add a Looting Point Component, leave everything blank but set the "LCollider" to be the Capsule Collider we've just created.'''
# '''Set the GameObject tag to be "RPG Creation Kit/LootingPoint"'''
The last step is to add a GameObject that will designate where the head of the Creature is.
So go inside the Armature all the way down to "Bip01 Head" and add a Cube GameObject as a child of it and do the following:
# '''Rename it "HeadPos", without the double quotes. This is mandatory.'''
# '''Set its Tag to "RPG Creation Kit/IgnoreWeapons".'''
# '''Set its Layer to "NPC".'''
# '''Set the Box Collider component to be Trigger.'''
# '''Add the "AI HeadPos" Component.'''
# '''Remove the Mesh Renderer and Mesh Filter.'''
And we have finished. If you did something wrong you'll know in the next section and you'll be able to fix it.


== Creating the Creature AI ==
== Creating the Creature AI ==

Revision as of 10:56, 25 April 2022

The Update 1.1 of the RPG Creation Kit introduced the Creature AI, which is a new type of AI Entity for the RPG Creation Kit built on top of the RckAI.

The Creature AI allows you to quickly setup any animated 3D model to be a AI Entity in the RPG Creation Kit, as opposed as the RckAI which requires you to setup a new Race and have your 3D models in a determined way.

In this tutorial, we are going to create the Skeleton featured in the Update video, made by IronicGame that you can download for free on the Asset Store.

This model, other than being super cool, comes also with even cooler animations - I suggest you download that asset and follow along with it during this tutorial, then you'll be able to setup any other 3D Model you want.

Setting up the Animator

The first step we're are going to take is to setup the Animator.

Before we start, you can download it from this link to see how the transitions and the states are made.

Open the SkeletonAC animator and let's focus on the "Parameters", every Animator you are going to make will need to use the same Parameters names and types as shown in this picture:

CANC 2.png


You'll also notice in the image above that I've only two States for the Default Animator Layer, "Idle-Walk" which is a BlendTree for the movement animation, and the "Fall 0" which is for the Death animation (if we're not going to use the ragdoll).

Before moving on, open the "Idle-Walk" BlendTree and make sure to set parameters to the just created "Sideways" and "Speed":

CANC 3.png


Now let's move to the "Layers" tab of the Animator, we have to add a new Layer (by right-clicking), let's call it "Upperbody". Click on the gear icon and set the Weight to 1, the Mask to Upperbody, the Blending to Override and you may want IK Pass as well.

CANC 4.png

The Upperbody is composed of:

  • New State: an empty state (must be the default).
  • Attack: the attack animation.
  • Fall: the same death animation of the Base Layer, used to make sure it gets played on the Upperbody too when the Creature dies.

Of course those transitions are parameterized, and they use the parameters we've created above. Make sure to look at the file above to see how the transitions are made.

Just a word on the Attack animations, in this case there is only one, so it was not meaningful to use the "AttackType" parameter, but keep in mind that your Creatures can chain attacks and you can control those with that parameter.

Setting up the Animations

The only job to get done to setup the animations is to set the Animation Events for the attacking animations, just like the Attacks of the RckAI.

Select in the Project Window the Attack1 animation and in the Inspector reach for "Events", you can add an Animation event by Right Clicking in the Timeline and clicking on "Add New Animation Event". For the Attack to work, you need at least three:

"AttackAnimationEvent": that should be where the attack is being executed (for example the blade has just started swinging).

"EndAttackAnimationEvent": that should be where the attack has ended (the swing ended).

"ResetAttackStateEvent": that should be at the end of the animation, it will tell that another attack can be performed.

Refer to the GIF below:

CANC 5.gif

Setting up the 3D Model

The next step is to setup the 3D Model. This is probably the most important part and the easiest one to forgot to something on, so let's go with order.

Drag and drop the "SKELETON" prefab in the Scene and remove the components "Animator" and "Player Controller" attached to it. It is important that the Creature AI model is structured in this way:

  • SKELETON (Parent Object)
    • Bip01 (Armature)
    • Mesh (Skinned Mesh Renderer)
BodyData Component


Add the "BodyData" Component to the "SKELETON" GameObject and set it up, the fields you have to assign are just:

  • My Avatar
  • R Hand
  • L Hand
  • Upper Chest
  • Hips

While the others can remain blank. Refer to the Image on the right:

Next-up, add a "Ragdoll" Component and leave it for now, we will come back to it later. (Add it even if you're not going to use Ragdoll)

Finally add an "AI Sounds" Component and insert the AudioClips you wish for your Creature's sounds.

Now it is time to create the Ragdoll, and we can do that with the Unity built in tool. Click in the top-bar on "GameObject->3D Object->Ragdoll and configure the window by inserting the correct bones of the Armature:

CANC 7.png

And click on Create.

Now if you're going to use the Ragdoll, now it's the time to come back at it. Look at the "SKELETON" GameObject, in the Inspector, and Right Click on the "Ragdoll Script", then select "Find Rigidbodies". That will fill the Rigidbody Array with the rigidbodies we've just created.

CANC 8.png

Great, now we have to designate those Rigidbodies to be the Body Parts of the Creature, that will make it hittable.

Select in the Hierarchy all the GameObjects we've put in the Ragdoll Window before and do the following:

  1. Change their Tag to be RPG Creation Kit/BodyPart
  2. Change their Layer to be BodyPart, and make sure to click "No, this object only" when asked to set the layer for all child.
  3. Add Component "BodyPart".


We have almost finished, now go through every GameObject and select the correct "This Body Part" in the "BodyPart" Component. You may want for the "Bip01 Pelvis" to select "Chest", for the "Bip01 LThigh/Calf" to be "Leg", and so on. What this does, is to designate the parts used for Locational Damage.

It is time to add the Looting Point. Add an Empty GameObject to "Bip01 Pelvis" (which is the Hip bone of the Skeleton), name it "LootingPoint" and do the following:

  1. Add a Capsule Collider Component and scale it accordingly to Creature's Size. Then make sure to set it as a Disabled Component.
  2. Add a Rigidbody Component and uncheck "Use Gravity", "IsKinematic" must be checked.
  3. Add a Looting Point Component, leave everything blank but set the "LCollider" to be the Capsule Collider we've just created.
  4. Set the GameObject tag to be "RPG Creation Kit/LootingPoint"


The last step is to add a GameObject that will designate where the head of the Creature is.

So go inside the Armature all the way down to "Bip01 Head" and add a Cube GameObject as a child of it and do the following:

  1. Rename it "HeadPos", without the double quotes. This is mandatory.
  2. Set its Tag to "RPG Creation Kit/IgnoreWeapons".
  3. Set its Layer to "NPC".
  4. Set the Box Collider component to be Trigger.
  5. Add the "AI HeadPos" Component.
  6. Remove the Mesh Renderer and Mesh Filter.


And we have finished. If you did something wrong you'll know in the next section and you'll be able to fix it.

Creating the Creature AI

Result & Extra

If your Creatures are triggering you warnings in the Console like "Animator Parameter "isDrawn" was not found", you can suppress those by adding the said parameters to the Animator, even if they're unused.