using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class crow2 : MonoBehaviour {
public Vector3 vectory = Vector3.forward; //当前物体前进方向
public Vector3 diyVectory = Vector3.zero;
public Vector3 totalF=Vector3.zero; //合力
public Vector3 separateF=Vector3.zero; //分离力
public Vector3 alignmentF = Vector3.zero; //队列力
public Vector3 gatherF = Vector3.zero; //聚集力
public float separateWeight = 1; //分离力权重
public float gatherWeight = 1f; //分离力权重
public float alignmentWeight = 1f; //分离力权重
public Animation anim;
public float m = 1;
public float checkInterval = 0.2f; //重复调用的时间
public List<GameObject> separateList = new List<GameObject>(); //
public float separateRadius=3f; //分离的半径
public List<GameObject> alignList = new List<GameObject>(); //
public float alignmentRadius = 6f; //聚集的半径
public List<GameObject>gatherList = new List<GameObject>(); //
public float gatherRadius = 6f; //聚集的半径
public Transform transfrom1; //一个目标
// Use this for initialization
void Start () {
transfrom1 = GameObject.Find("tran").transform;
&
using System.Collections.Generic;
using UnityEngine;
public class crow2 : MonoBehaviour {
public Vector3 vectory = Vector3.forward; //当前物体前进方向
public Vector3 diyVectory = Vector3.zero;
public Vector3 totalF=Vector3.zero; //合力
public Vector3 separateF=Vector3.zero; //分离力
public Vector3 alignmentF = Vector3.zero; //队列力
public Vector3 gatherF = Vector3.zero; //聚集力
public float separateWeight = 1; //分离力权重
public float gatherWeight = 1f; //分离力权重
public float alignmentWeight = 1f; //分离力权重
public Animation anim;
public float m = 1;
public float checkInterval = 0.2f; //重复调用的时间
public List<GameObject> separateList = new List<GameObject>(); //
public float separateRadius=3f; //分离的半径
public List<GameObject> alignList = new List<GameObject>(); //
public float alignmentRadius = 6f; //聚集的半径
public List<GameObject>gatherList = new List<GameObject>(); //
public float gatherRadius = 6f; //聚集的半径
public Transform transfrom1; //一个目标
// Use this for initialization
void Start () {
transfrom1 = GameObject.Find("tran").transform;
&

这篇博客介绍如何在Unity环境中实现群组算法。通过`InvokeRepeating`函数每三秒为对象设置一个新的随机位置,实现了群体中个体随机移动的效果。`change`方法使用`Random.Range`生成新的坐标,并更新`transform.position`来改变对象的位置。
最低0.47元/天 解锁文章
4282

被折叠的 条评论
为什么被折叠?



