Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active February 3, 2017 04:13
Show Gist options
  • Select an option

  • Save tsubaki/7e22cec8527c534e4c7a to your computer and use it in GitHub Desktop.

Select an option

Save tsubaki/7e22cec8527c534e4c7a to your computer and use it in GitHub Desktop.
WaypointCircuitでパスを決めてキャラクターを動かす最小限モデル
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Utility;
[RequireComponent(typeof(WaypointProgressTracker))]
public class WaypointAgent : MonoBehaviour
{
private WaypointProgressTracker tracker = null;
[SerializeField, Range(0, 10)]
protected float speed = 1;
void Start()
{
tracker = GetComponent<WaypointProgressTracker>();
}
void Update()
{
Vector3 targetPosition = tracker.progressPoint.position + tracker.progressPoint.direction;
transform.position = Vector3.MoveTowards( transform.position, targetPosition, speed * Time.deltaTime);
}
}
@tsubaki
Copy link
Author

tsubaki commented Apr 22, 2015

使い方

  1. メニュー>Assets>ImportPackage>UtilityでUtilityパッケージをインポート
  2. 空のオブジェクト(Path)を作成し、通ってほしいポイントに子オブジェクトを設定
  3. PathオブジェクトにWaypointCircuitを設定し、Assin using all child objectsをクリック
     →子オブジェクト一覧がパスとして登録される。
  4. パスを走り回るオブジェクトにWaypointAgentを設定
  5. WaypointProgressTrackerのCircuitにPathオブジェクトを設定
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment