ue4 riding system guide€¦ · ridercharacter reference, animalcharacter reference. these...

21
Date creation: 7-12-2019 Last adjustment: 9-12-2019 Author: Dirk Peeters (Jengske_BE) Contact: [email protected] Website: https://www.worldwidegamersunited.com/ Video version: PlayList UE4 version used: 4.23 Type: Blueprints Applying to: New project or Own project UE4 Riding System Guide 1 Overview 2 Project setup 3 Variables overview (Master blueprints) 4 Assets selection 5 Create the master Animal BP 6 Create the master Rider BP 7 Create the Animal AnimBP 8 Create the Rider AnimBP 9 Select and prepair the animations 10 Animal_Master_BP: adding the code 11 Rider_Master_BP: adding the code 12 Setting up the Animation blueprints 13 What now? 1 Overview Welcome to my riding system guide, in this guide we will be setting up a rider/horse combination. We will set-up the basics. Once this is done you have the knowledge to improve it to your own needs. For those already having a project and want to implement riding basics, this guide is both for a new or already created project. We will provide this guide as a pdf version and a playlist on my Youtube channel. If you find a better way in doing, you can send me a mail and i will test and adjust this guide. Check always the last date on the adjustment date as i will be updating this guide during my development of my RidingSystem. If you want to discuss something you can find me on our Teamspeak server by going to our website main page. On the left side you see the WGU Teamspeak to connect to. Just click to connect. (you must have Teamspeak installed). Look for Jengske_BE

Upload: others

Post on 22-May-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Date creation: 7-12-2019Last adjustment: 9-12-2019Author: Dirk Peeters (Jengske_BE)Contact: [email protected]: https://www.worldwidegamersunited.com/ Video version: PlayListUE4 version used: 4.23Type: BlueprintsApplying to: New project or Own project

UE4 Riding System Guide1 Overview2 Project setup3 Variables overview (Master blueprints)4 Assets selection5 Create the master Animal BP6 Create the master Rider BP7 Create the Animal AnimBP8 Create the Rider AnimBP9 Select and prepair the animations10 Animal_Master_BP: adding the code11 Rider_Master_BP: adding the code12 Setting up the Animation blueprints13 What now?

1 Overview

Welcome to my riding system guide, in this guide we will be setting up a rider/horse combination. We will set-up the basics. Once this is done you have the knowledge to improve itto your own needs.

For those already having a project and want to implement riding basics, this guide is both for anew or already created project.

We will provide this guide as a pdf version and a playlist on my Youtube channel.If you find a better way in doing, you can send me a mail and i will test and adjust this guide.

Check always the last date on the adjustment date as i will be updating this guide during my development of my RidingSystem.

If you want to discuss something you can find me on our Teamspeak server by going to our website main page. On the left side you see the WGU Teamspeak to connect to. Just click to connect. (you must have Teamspeak installed). Look for Jengske_BE

Page 2: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

2 Project setup

As mentioned above you can use this in your own project, just follow along. But first make a backup of your current project.For those starting fresh.Create a new ThirdPerson Blueprint project, give it a name and hit Create. Open it.

We now first go to go to the project settings > input. And setup our Bindings.Add a Action map by clicking the + sign. And call it 'ToggleMount' assign key 'M'.

Go to the Content Browser. We now going to setup a default directory structure for our project.Create a new folder, call it 'RidingSystem' click to open the new folder. Optional you can assign a color to the map by right clicking on the folder and Set Color.

Create these folders inside the ridingsystem. (> = sub folder, | = folder1 | folder2 | ....)

MasterBlueprints > Masters | Childs

Animations > AnimalCharacter | PlayerCharacter > Male | Female

AnimBP > AnimalCharacter | PlayerCharacter > Male | Female

Blendspaces > AnimalCharacter | PlayerCharacter > Male | Female

Montages > AnimalCharacter | PlayerCharacter > Male | Female

Maps

When you save and have empty folders, they will be removed, but during the guide this structure we follow.

Now we will list the variables we will be using and start getting our assets.

Tip: When you move/copy/rename stuff, don't forget to clear left behinds as redirectors. To fix this, right click on your content folder > Fix up Redirectors in folder. You can set a filter also if you want, Filters> Other filters >Show Redirectors.

Page 3: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

3 Variables overview (Master blueprints)

As we will put all in categories, i wil quick show you how to make sub categories. (just copy this ' RidingSystem | General ') and paste it on the variable or function category, in the details panel. I will write the sub category behind the variable.

For both animal and rider:

Speed, type = float, cat = AnimBPDirection, type = float, cat = AnimBPAnimBP_Ref, type = Anim Instance (reference), cat = AnimBPAnimInstanceClass, type = Object (class reference), cat = AnimBPMounting, type = Boolean, cat = AnimBPDismounting, type = Boolean, cat = AnimBP

Animal only:

bCanMount, type = Boolean, cat = InteractionHasDriver, type = Boolean, cat = InteractionRider, type = Character(reference), cat = Interaction

Rider only:

isMounted, type = Boolean, cat = AnimBPCanMove, type = Boolean, cat = InteractionTracedActor, type = Actor(reference), cat = InteractionMaxUseDistance, type = float, cat = Interaction , default value = 1000.AnimalRef, type = Master_AnimalBP(reference), cat = InteractionNULLACTOR, type = float, cat = Core

These are only in the Master Blueprints, once we start on the AnimBP(s) we add mainly the same variables but wait till we get to that point.

4 Assets selection

Now we go import the assets we need, what we need?- A animal to ride and a rider to put on top of the animal.- Animal must have a good set of animations to be used for walking, direction L R, Jumping- Rider must have all animations as the animal for the movement and directions to have the best result. Also a mount/dismount animation.

There is a differince between a animal in distance or as a AI using for example the Animal Behavior Kit, now we realy need to have more detailed animations for movements. So we can create smooth looking movements. The better the set of animations provided on your asset the better result you get in the end.

I will be using the following assets during the rest of this tutorial series.

– Kasqir Character by Quang Phan

– Linhi Character by Quang Phan

Optional: i will also prepair this for the Animal Behavior Kit

If you want animals in your game this pack is realy a must have.I setup a landscape but you can use your own test setup.

Now go selecting your animations and move or copy them to the correct folder as mentioned above. Same for the rest you want to be using, put it in the correct folder under the riding system.

Page 4: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

5 Create the master Animal BP

Go into the 'MasterBlueprints > Masters' folder and create a new Blueprint, type = Character, name this 'Master_Animal_BP' or rename/move/copy the Default Third Person Blueprint as thisalready has the movement setup. Animal/rider has the same default movement and camera setups.

Now add all variables to the Animal. Put them direct in the correct category to keep all nice and clean. If you start a freash blueprint, just copy the movement out a example character.

For those copy, bla bla. Remove the VR stuff and other code by Epic we do not need, its a Animal. Mainly movement we focus on no eating drinking or so.

Now we first go add some components, select the Capsule and add a box/sphere collider, name it 'InteractionTrigger'. Go to the details panel still selecting the new component. And check the Collission Preset ' OverlapAllDynamics'.

Now add a Scene component to the Capsule and name this 'GetDownLocation'

This will be the location were the rider stand when the dismount animation is done.I will show how we set the position in the video version, same for adding the socket.

So now we can select the mesh, set it to your animal. And open the Skeleton.In the Skeleton Tree find a bone were you think the Rider must sit.

Add a socket to that bone and call this 'RIDER', save and close for now.

For now this was the basic setup as for setting up the Animalcharacter base. you can add yourown sockets for holding weapons and gears later. Also positioning we do along the way.Remember to do this on all your animal skeletons you want to ride. Compile and save

In the video i go over the details panel

6 Create the master Rider BP

Go into the 'MasterBlueprints > Masters' folder and create a new Blueprint, type = Character, name this 'Master_Animal_BP' or rename/move/copy the Default Third Person Blueprint as thisalready has the movement setup. Or use your character_BP.

Now add all variables to the Rider. Put them direct in the correct category to keep all nice and clean. Again clean all not needed code, this depends on what your character must do.

For Animal and Rider:

On both characters select your movementComponent and go in the detailspanel > character movement(rotation settings)

Now select the Spring arms and set camera settings to

Page 5: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

In the video i go over the details panel

For the rest leave it like it is for now. Compile and save

7 Create the Animal AnimBP

If you do not already have a Animation Blueprint setup, now its time to create one.Go to the AnimBP > AnimalCharacter folder and create a new Animation Blueprint, select your Animal skeleton and click create, name this YourAnimalBPName_AnimBP, 'Animal_Master_AnimBP'. Depending on your assets you can share the same anim blueprint as long as the skeleton is the same, otherwise you need to create this per skeleton based. Or try retargeting all. Same goes for the Ridercharacter.

Lets add the variables in the EventGraph.

Check the variables list Variables overview (Master blueprints)

We add: Speed, Direction, IsInAir bool, AnimalRef, RiderRef, CanMount, HasDriver.Compile and save

8 Create the Rider AnimBP

If you do not already have a Animation Blueprint setup, now its time to create one.Go to the AnimBP > PlayerCharacter > Male | Female folder and create a new Animation Blueprint, select your Player skeleton and click create, name this YourRiderBPName_AnimBP, 'Rider_Master_AnimBP'.

Lets add the variables in the EventGraph.

Check the variables list Variables overview (Master blueprints)

We add: Speed, Direction, IsInAir bool, isMounted bool, Mounting bool, Dismounting bool, RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BPCompile and save

9 Select and prepair the animations

Before we go dive into the coding we first go setup all our animations.

For the Animal and Rider create the onHorse blendspaces, even the idle,walk run if you do not have them. You can also create some montages but for the moment we only using the animBPand animations and blendspaces.

Same as a other character we need to create our Animation Blueprint and set the default movement tree, from there we build furter.

Ok now we are ready to add the code.

10 Animal_Master_BP: adding the code

Open the master animal blueprint. Create a new function name this 'SetAnimBP'

Page 6: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Now create a other function and name this 'UpdateSpeedAndDirection'

Create a new eventGraph name this 'RidingSystem'.Add OnBeginPlay event and connect the function 'SetAnimBP to it.

Page 7: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Now select the 'InteractionTrigger' and create the Onbegin and OnEnd overlap events like so

ATMRider is the master_Rider_BP. Create a Custom event and name this 'DismountEvent'.

Page 8: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Full view

Now add the ToggleMount action and connect the DismountEvent

Page 9: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before
Page 10: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

We now go add Event Tick. Like so.

Movement code

Page 11: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Now select your mesh and set the collision to 'BlockAll' compile and same, almost done.Assign your animBP to the mesh again compile save and close.

11 Rider_Master_BP: adding the code

The rider has less code to ad so we start by creating the functions first.

Create a function called 'TraceToActor'

Page 12: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before
Page 13: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

The two other functions to create 'SetAnimBPRef' and 'UpdateSpeedAndDirection'

Same here create a new EventGraph 'RidingSystem', Add a Custom event called 'MountEvent'

Page 14: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Select all and do 'Collapse nodes'. Go to the ridingGraph and setup the connections

Page 15: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Also here set your AnimBP for the Rider mesh. When you play nothing happens as we need to now start working on the Animation Blueprints. Compile and save. Close the master blueprints for now and open the AnimBP(s).

12 Setting up the Animation blueprints

We open the animal animBP first. The Event Graph.

Page 16: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

The AnimGraph, simple default movement setup.

Compile and save, the animal is done.

Page 17: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Now the last part the Rider AnimBP. Open it and create a function called 'UpdateSpeedAndDirection' i created this to keep all in one place.

Go to the EventGraph.

Now go to the AnimGraph, create the state machine(s)

Page 18: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

OnGround:

OnAnimal:

Page 19: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

Transitions Mounting:

Transitions Dismounting:

Mounting plays mount animation, Dismount the unmount animation. Idle the Onhorse

Page 20: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

blendspace. For the nexxt transition i check on speed > 0, speed <=0.

Now before we forget create a new GameMode or use yours, set the rider as default

Page 21: UE4 Riding System Guide€¦ · RiderCharacter reference, AnimalCharacter reference. These reference to your master_Type_BP Compile and save 9 Select and prepair the animations Before

playercharacter. Drag in the Horse and start testing. If we did not forgot something you now have a rider that rides the horse.

13 What now?

The goal to have our character ride a animal is done, we can now start fine tuning the animations and expand them with shooting, add sounds to the animal and mutch more but, thats not all what about a HorseWagon how could we implement this in the current state as also a basic wagon riding. We will continue on our project and once we got it working come back and expand the guide.

For now thanks and if you have any comment or better way's to do this let us know by sendinga mail to [email protected] or visit our Teamspeak server.