コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        Rigidbody rb = GetComponent <Rigidbody> ();
        //find target (closest to position that will be held in X time
        GameObject target = TargetHelper.findClosestPlayer(rb, rb.velocity.magnitude * predictionDetection);
        //get direction to target
        Vector3 dirToTar = rb.transform.position - target.transform.position;

        /*	//display marker
         *      Destroy(refr);
         *      refr = Instantiate(prefab, -(rb.position+dirToTar.normalized), Quaternion.identity);
         */
        //set course and compensate for current velocity (adjust/tweek for focusing on target or balancing out momentum)
        rb.AddForce((-(dirToTar * maneuverability + rb.velocity).normalized) * acceleration);
    }