2016年5月11日 星期三

AI 基本追隨物件 (非閃避障礙物)

之前程式搭配連結 
-----------------------------------------------------------------
SteeringForSeek  類別(功能: 追隨)
-----------------------------------------------------------------
using UnityEngine;
using System.Collections;

public class SteeringForSeek : Steering {

    public GameObject target;           // 需要尋找的目標物體
    private Vector3 desiredVelocity;    // 預期速度
    private Vehicle vehicle;            // AI數據
    private float maxSpeed;             // 最大速度
    private bool isPlanar;              // 二維平面上

    void Start() {
        // Vehicle資訊,取得AI最大速度及二維平面
        vehicle = GetComponent<Vehicle>();
        maxSpeed = vehicle.maxSpeed;
        isPlanar = vehicle.isPlanar;
    }

    public override Vector3 Force()
    {
        desiredVelocity = (target.transform.position - transform.position).normalized * maxSpeed;
        if (isPlanar)
            desiredVelocity.y = 0;
        return (desiredVelocity - vehicle.velocity);
    }
}

沒有留言:

張貼留言