This article relates to the game "Dota 2". Click here for more information.
This article relates to the SDK/Workshop Tools for "Dota 2 Workshop Tools". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Dota 2 Workshop Tools/Scripting/Data Driven Motion Controller Example

From Valve Developer Community
Jump to: navigation, search

Note.pngNote: This page is cross posted from /r/Dota2modding. [1]

Example Video

Now that I have your attention, let's talk. The data-driven ability system is seriously cool and there's a lot of neat stuff we can make with it. There's also a couple of data-driven effects that weren't listed in any of the examples or documentation. One of these is "ApplyMotionController".


So what does ApplyMotionController do? I couldn't find any references to it anywhere, so I decided to find out for myself. First, let's start with the format. The format looks a little something like this:

"ApplyMotionController"
    {
        "TARGET" "TARGET"
        "ScriptFile"	 "scripts/vscripts/your_script_here.lua"
        "HorizontalControlFunction"	"TestGravityFunc"
        "VerticalControlFunction" "TestGravityFunc"			
    }

There could be other parameters too, but this appears to be enough to make it work. After some testing, I found that ApplyMotionController repeatedly calls both the horizontal and vertical control functions several times per second. Return values seemed to have no effect on the behavior. As for the function itself:

function TestGravityFunc(args)
        local targetPos = args.target:GetAbsOrigin()
        local casterPos = args.caster:GetAbsOrigin()

        local direction = targetPos - casterPos
        local vec = direction:Normalized() * 3.0
	
        args.caster:SetAbsOrigin(casterPos + vec)
    end

It's a pretty simple function. It gets the direction of the caster to the target, and moves the caster 3 units in that direction. Since the function is being called so often, the result is a pseudo-gravitational pull towards the target.

However, I believe there is a lot more to the effect than what I've done so far. For starters, I can't find any difference between the HorizontalControlFunction parameter and the VerticalControlFunction parameter. I imagine there should be some way to have these functions return some sort of differing movement command to the target, but so far I haven't figured that out yet. There's also a CDOTA_BaseNPC:InterruptMotionControllers(bool) function which I've tried out, although it doesn't appear to do anything.