Example #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 accel = steeringBasics.interpose(target1, target2);

        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Vector3 accel = wander.GetSteering();

        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #3
0
        // Update is called once per frame
        private void Update()
        {
            var accel = GetSteering();

            _steeringBasics.Steer(accel);
            _steeringBasics.LookWhereYoureGoing();
        }
Example #4
0
    void Update()
    {
        Vector3 accel = evade.GetSteering(target);

        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        Vector3 accel = steeringBasics.seek(target.position);

        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        Vector3 accel = steeringBasics.Arrive(targetPosition);

        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #7
0
    void Update()
    {
        // 得到线性加速度
        Vector3 accel = flee.getSteering(target.position);

        // 设置刚体速度
        steeringBasics.Steer(accel);
        // 设置朝向
        steeringBasics.LookWhereYoureGoing();
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        // 得到 线性加速度
        Vector3 accel = pursue.getSteering(target);

        // 设置刚体速度
        steeringBasics.Steer(accel);

        // 朝向
        steeringBasics.LookWhereYoureGoing();
    }
Example #9
0
        // Update is called once per frame
        private void FixedUpdate()
        {
            var accel = Vector3.zero;

            accel += _cohesion.GetSteering(_sensor.Targets) * CohesionWeight;
            accel += _separation.GetSteering(_sensor.Targets) * SeparationWeight;
            accel += _wander.GetSteering();

            _steeringBasics.Steer(accel);
            _steeringBasics.LookWhereYoureGoing();
        }
Example #10
0
        // Update is called once per frame
        private void FixedUpdate()
        {
            if (IsWanderingTarget == false)
            {
                return;
            }

            var accel = GetSteering();

            _steeringBasics.Steer(accel);
            _steeringBasics.LookWhereYoureGoing();
        }
Example #11
0
        private void FixedUpdate()
        {
            if (IsEvadingTarget == false || Target == null)
            {
                return;
            }

            var accel = GetSteering(Target);

            _steeringBasics.Steer(accel);
            _steeringBasics.LookWhereYoureGoing();
        }
Example #12
0
        // Update is called once per frame
        private void FixedUpdate()
        {
            if (AvoidingWallAllTheTime == false)
            {
                return;
            }

            var accel = GetSteering();

            _steeringBasics.Steer(accel);
            _steeringBasics.LookWhereYoureGoing();
        }
Example #13
0
        /// <summary>
        /// returns true while still following a path. Returns false when it arrives
        /// </summary>
        /// <returns></returns>
        public bool DoFollowPathStep()
        {
            RequestPath(GetTarget().transform);
            var followingPath = true;
            var pos2D         = Path.Vector3ToVector2(_myTransform.position);

            if (_path == null) // we are still waiting for the path to be calculated
            {
                return(true);  // we are technically still following the path (we have not arrived)
            }
            if (_pathIndex > _path.TurnBoundaries.Length || _path.FinishLineIndex == -1)
            {
                _pathIndex = 0;
                return(true);
            }

            // loops through the turn boundaries till it founds the last boundary it has crossed.
            // This solves the pathing problem if we move through several turn boundaries for each turn.
            while (_path.TurnBoundaries[_pathIndex].HasCrossedLine(pos2D))
            {
                // we arrived at the end of the path
                if (_pathIndex >= _path.FinishLineIndex)
                {
                    break;
                }

                _pathIndex++;
            }

            if (Vector3.Distance(transform.position, GetTarget().position) < 1f)
            {
                GetComponent <Rigidbody>().velocity = Vector3.zero;
                followingPath = false;
            }

            // rotate and move the unit to the next point
            if (followingPath)
            {
                var acc = _arrive.GetSteering(_path.LookPoints[_pathIndex]);
                if (Math.Abs(acc.x) < 0.01f && Math.Abs(acc.z) < 0.01f) // something went wrong with the pathfinding and we are stuck. Do a new plan.
                {
                    if (GetTarget() != null)
                    {
                        RequestPath(GetTarget().transform, true);
                    }
                }
                _steering.Steer(acc);
                _steering.LookWhereYoureGoing();
            }
            return(followingPath);
        }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        // 加速度(有碰撞 就避免碰撞)
        Vector3 accel = colAvoid.GetSteering(colAvoidSensor.targets);

        // 没有任何碰撞的时候就  漫游
        if (accel.magnitude < 0.005f)
        {
            accel = wander.GetSteering();
        }

        // 速度
        steeringBasics.Steer(accel);
        // 朝向
        steeringBasics.LookWhereYoureGoing();
    }
Example #15
0
        // Update is called once per frame
        private void Update()
        {
            //get the best hidePosition
            var hideAccel = GetSteering(Target, Objs, out var hidePosition);

            //make sure we avoid the walls when we move to the hidding spot
            var accel = _wallAvoid.GetSteering(hidePosition - transform.position);

            //if the acceleration from the wall avoidance is too small we use the one returned by out Hide behavior
            if (accel.magnitude < 0.005f)
            {
                accel = hideAccel;
            }

            _steeringBasics.Steer(accel);
            _steeringBasics.LookWhereYoureGoing();
        }
Example #16
0
    void Update()
    {
        path.draw();

        // 执行原路返回的逻辑
        if (reversePath && isAtEndOfPath())
        {
            path.reversePath();
        }

        // 计算线性加速度
        Vector3 accel = followPath.getSteering(path, pathLoop);

        // 设置刚体速度
        steeringBasics.Steer(accel);
        // 朝向
        steeringBasics.LookWhereYoureGoing();
    }
Example #17
0
    void Update()
    {
        // 得到加速度   躲在障碍物后面,同时不被目标看到
        Vector3 hidePosition;
        Vector3 hideAccel = hide.GetSteering(target, obstacleSpawner.objs, out hidePosition);

        // 如果撞墙要 解决
        Vector3 accel = wallAvoid.GetSteering(hidePosition - transform.position);

        // 没有撞墙 (说明如果撞墙先解决撞墙)
        if (accel.magnitude < 0.005f)
        {
            accel = hideAccel;
        }

        // 设置速度 和 朝向
        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #18
0
    void LateUpdate()
    {
        Vector3 targetPos;
        // 偏移追随加速度  和  分隔加速度
        Vector3 offsetAccel = offsetPursuit.getSteering(target, offset, out targetPos);
        Vector3 sepAccel    = separation.GetSteering(sensor.targets);

        // 速度会  受到两个方面的影响
        steeringBasics.Steer(offsetAccel + sepAccel);

        /* 如果我们还在前往,那就要朝向我们要去的地方,其他的方向和我们的形成目标是一样的 */
        if (Vector3.Distance(transform.position, targetPos) > groupLookDist)
        {
            steeringBasics.LookWhereYoureGoing();
        }
        else
        {
            steeringBasics.lookAtDirection(target.rotation);
        }
    }
Example #19
0
    // Update is called once per frame
    void Update()
    {
        Vector3 accel = Vector3.zero;

        // 集群加速度
        accel += cohesion.GetSteering(sensor.targets) * cohesionWeight;
        // 分隔加速度
        accel += separation.GetSteering(sensor.targets) * separationWeight;
        // 速度匹配加速度
        accel += velocityMatch.GetSteering(sensor.targets) * velocityMatchWeight;

        // 如果没有那些 影响, 就漫游好了
        if (accel.magnitude < 0.005f)
        {
            accel = wander.GetSteering();
        }

        // 设置刚体速度  和  朝向
        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
Example #20
0
    void Update()
    {
        // 调试
        path.draw();

        // 是否原路返回
        if (isAtEndOfPath())
        {
            path.reversePath();
        }

        // 躲避 加速度
        Vector3 accel = colAvoid.GetSteering(colAvoidSensor.targets);

        // 不需要躲避 就沿着路径走
        if (accel.magnitude < 0.005f)
        {
            accel = followPath.getSteering(path);
        }

        // 设置刚体速度 和 朝向
        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();
    }
    // Update is called once per frame
    void Update()
    {
        // 到达终点了, 原路返回
        if (isAtEndOfPath())
        {
            path.reversePath();
        }

        // 得到加速度 (要躲避墙)
        Vector3 accel = wallAvoidance.GetSteering();

        // 沿着路径走了 (约定没有碰撞时 加速度为0了)
        if (accel.magnitude < 0.005f)
        {
            accel = followPath.getSteering(path);
        }

        // 设置刚体 和 朝向
        steeringBasics.Steer(accel);
        steeringBasics.LookWhereYoureGoing();

        // 调试
        path.draw();
    }