Move to Target

Yao Yao
Data Mining the City
3 min readNov 13, 2019

Datamining the City — Individual Project

Poem~

-Before you have a target, you may often just wander.

-You can get to it faster if you become richer.

When we consider moving to a certain target, no matter a location or a moving spot. In some cases, it can be simplified as a chasing ball game. And there are many factors/parameters influence how we get to our destination, for example, we always try to arrive there faster, and the richer we are, the faster we can be.

Agents Build

Some times there is a decision tree frame.

Otherwise, we can have some factors that in a parallel structure to control the agent.

It’s too early to say the more complex, the better the simulation is, but for this time we just based on a simple decision tree to do this.

Simulation

First, there is a basic simulation that is using a “typical” parameter set.

Move to Target

Then the “money” is changed, which means the moving speed of agents will increase when they are richer.

Change the “Money”

And what if the attractivity of the targets? In real life, this could represent the willingness of moving to the destination.

Change the “Willingness”

The spatial limitation is also a factor. What if the targets are more likely to go to the edge area of the platform?

Going to “Edge Area”

Code Vignette

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Movement
{
[TaskCategory("AgentSystem")]
public Shared String tag;
[Tooltip("The speed of the agent")]
public SharedFloat speed;
[Tooltip("Search area")]
public SharedFloat search;
[Tooltip("Touched distance")]
public SharedFloat touchedDis;
private GameObject[] targetObjects;
private Vector3 prevDir;
public override void OnStart()
{
base.Onstart();
targetObjects = GameObject.FindGameObjectsWithTag(tag.Value);
}

//Follow the target

public override TaskeStatus OnUpdate()
{
if (target.Value == null)
}
var targetPosition = target.Value.transform.position;
if ((targetPosition - lastTargetPosition).magnitude >= moveDistance.Value)
{
SetSestination(targetPosition);
lastTargetPosition = targetPosition;
hasMoved = true;
}
else
{
if (hasMoved && (targetPosition - transform.position).magnitude < moveDistance.Value)
{
Stop();
hasMoved = false;
lastTargetPosition = targetPosition;
}
}
return TaskStatus.Running;
}

--

--