HOW-TO: Add moving entities

moving_entity.jpg

Learn how to add moving Gameplay Entities onto the level.

These steps can be applied to a ship, a plane or a flying whale. In this guide we will start small by adding a boat to the level with a mesh and dynamic colliders. Later we will also set an animation and set its curve.


Setup

First enable the debug filter AnimatedProperties so you can actually see them in the Editor (https://cdprojektred.atlassian.net/wiki/spaces/W3REDkit/pages/6329000).

847d785c-6817-4aaf-acd6-658c4790ae1f.png

Create Entity Template

Then create a new Entity Template. Change its class to GameplayEntity - this class and its children have access to PropertyAnimation, which we will be using for our movement.

You can backtrack to this https://cdprojektred.atlassian.net/wiki/spaces/W3REDkit/pages/6326348 guide to learn more about entities.


Add mesh

Add a mesh into the entity. Find the boat_row_wooden_old.w2mesh file in the Asset Browser.

Select the file and drag it from the Asset Browser into the entity template’s graph. Choose Rigid Mesh Kinematic in the Create Mesh Component popup.


Add dynamic collider

Add a dynamic collider component (CDynmicColliderComponenet0) on the Entity’s graph and make sure the useInWaterDisplacement property is set to true (the component will displace water).

On the graph, connect the Mesh and the Dynamic Collider by attaching them to each other via Link using CHardAttachment.

This will make sure the collider follows the mesh.

 


Add entity to level

Time to place the Entity on the level (in the Editor’s viewport).

Go to the Entity’s properties. You can add a new PropertyAnimation with the CPropertyAnimationSet class.

You need to choose which components the PropertyAnimation will affect. Click on the icon in the CGameplayEntity > SPropertyAnimation. A pop-up with a list of properties should appear. Select the Base Objects > transform [EngineTransform].

It’s also possible to move specific components, but we want the whole boat to move.


PropertyAnimation

Name the animation move. Tick the “playOnStartup” so we see it immediately.

Otherwise that animation would have to be called from scripts or specifically pointed out in the quest graph.


Curve

Now, click on the curve field and on the right side the wiggly, snake-ish curve icon.

You should now see a debug view of the curve on the level - similar to the one on the screenshot below.

If it’s not visible, make sure you enabled the debug filters for Animated Properties (first step of this guide).

You can change the totalTime of the whole movement under SMultiCurve.

Let’s change it to 30s.

And now we can move the curves points around on the level.

You can right click on a control point to Add a new point before/after the current one. You can also Enable looping, which will connect the start and end points.


Test curve

You can also check how the movement would look in the game via Visualization > Enable Curve Run.

In the Editor you will not see the Entity itself but just a red cube splashing around in water.


Create a loop

Now add a couple more points and Enable looping.

Some useful shortcuts: Y key can be used to snap the point to the mouse position, just like with actors. Coma and Dot keys (, and .) can be used to cycle through the points when one is selected.

You will notice in game that the boat is not actually turning.

To fix this we need to Enable automatic rotation from direction recalculation. Right click on a point and choose this option:


Done!

Now the boat should rotate properly!


Up for a challenge?

For a more complex entity example, you can try setting up movement for this boat paddler available in:

  • prologue_village level - living_world\scenes\entities\boat_man_prologue_02.w2ent

Good luck!

 

______________________________________
The Witcher 3: Wild Hunt Complete Edition © 2024 CD PROJEKT S.A. Published by CD PROJEKT S.A. Developed by CD PROJEKT RED. CD PROJEKT®, The Witcher®, REDengine® are registered trademarks of CD PROJEKT Capital Group. All rights reserved. The Witcher game is set in the universe created by Andrzej Sapkowski in his series of books. All rights reserved.