Thursday, June 10, 2010

Ambient behaviour: Movement

I recently received an enquiry regarding ambient behaviours in Dragon Age.  Ambient behaviours are a simple means of making your world feel a little more alive by having the NPCs in it wander around and perform actions. I'm just going to approach this from a fairly simple perspective, as I haven't delved into the area in detail, but hopefully I can provide some useful information. Firstly, this page on the toolset wiki gives an excellent overview of how ambient behaviours work, but I'll try and add a few examples and demonstrations in my explanation.

The first thing to do with your NPC is to set the variable AMBIENT_SYSTEM_STATE. In most cases, you'll just want to set this to 1. There are some cases where you will want to set it to one of the other values (as listed on that page - 2 or 4 for looping animations), but in general, 1 is the setting you'll be using most of the time. So select your NPC in the area editor, click the variables button and then change that value to 1.


The first part of ambient behaviour is NPC movement; getting them to move around a level, imitating the bustle of regular activity. This kind of activity is achieved quite easily. AMBIENT_MOVE_PATTERN is the primary variable controlling movement. It determines the pattern and type of movement that the NPC will undertake.

I'll go through the patterns as they're listed in the wiki. These are mostly self-explanatory (though I'll explain waypoint usage).

0 (AMBIENT_MOVE_NONE): No ambient movement - only if you want the NPC to stand still.
1 (AMBIENT_MOVE_PATROL): Patrol waypoints (1, 2, 3, 2, 1, ...)
2 (AMBIENT_MOVE_LOOP): Loop through waypoints (1, 2, 3, 1, 2, 3, ...)
3 (AMBIENT_MOVE_WARP): Jump creature from the last waypoint to the first (1, 2, 3, jump to 1, 2, 3, ...)
4 (AMBIENT_MOVE_RANDOM): Move to a random waypoint other than the one the creature is currently at
5 (AMBIENT_MOVE_WANDER): Move to random location within 10m of home location
6 (AMBIENT_MOVE_WANDER_FAR): Move to random location within 30m of home location
7 (AMBIENT_MOVE_PATH_PATROL): Patrol all waypoints using CommandMoveToMultiLocations (1,2,3,2,1,...)
8 (AMBIENT_MOVE_PATH_LOOP): Loop through all waypoints using CommandMoveToMultiLocations (1,2,3. 1,2,3)
9 (AMBIENT_MOVE_ONCE): Walk through the waypoint set once (1-2-3)

In order to select the desired behaviour, simply enter this number as the value of the AMBIENT_MOVE_PATTERN variable. Also note that you can make the NPC run by adding 100 to that number.

5 and 6 are the two that don't require waypoints, so let's cover those first. These two options are simple.  All you have to do is set the variable to 4 or 5, and the NPC will happily wander about the level, either 10 of 30 metres from their initially placed location.

The waypoint based movement modes require you to create waypoints within the area for the NPC to follow with specific tags. Objects within the game have a "tag" which act as a (non-unique) identifier for the item. The idea is that you create a sequence of waypoints with numbered tags and the NPC will walk among them. You can set the format of the tag for your waypoints by using the AMBIENT_MOVE_PREFIX variable on the NPC. By default, this is in the form ap_.  Again, taking the example from the wiki, this would mean the creature's tag is cr_dog then the system will look for waypoints with tags ap_cr_dog_01, ap_cr_dog_02.  It appears you can have the numbers after the tag in the form 01, 02, etc, or simply use 1,2,3, etc, as both appear in the main campaign. (As can be seen in the waypoint list from Ostagar on the right)

When using these waypoint systems, I'm not sure if there is a distance limit on how far away the next waypoint can be. It may be wise not to space waypoints too far from each other.  I'm also not certain of the benefit of using 7 or 8 over 1 or 2. Option 9 I believe is what was used for Duncan at Ostagar.  After he talks to you in the initial cutscene/conversation of the area, he makes his may to the bonfire and then stops there.  So this option allows you to set waypoints to make someone move to a specific location and then stop there. However, you'll likely need to use some scripting in order to make it work properly - as you'll want to activate it after a particular event. If people are interesting in modifying these behaviours via script functions, then I could potentially write a short tutorial on that as well.



This has unexpectedly turned into a long post... so I might have to cover the animation part of ambient behaviour another day!

No comments:

Post a Comment