예제 #1
0
    //逻辑更新
    public virtual void update()
    {
        //死亡后达到指定时间,则该角色可以被移除
        if (IsKilled)
        {
            RemoveTimer -= Time.deltaTime;
            if (RemoveTimer <= 0)
            {
                CanRemove = true;
            }
        }

        //武器更新
        if (Weapon != null)
        {
            Weapon.update();
        }
        //AI更新
        if (AI != null)
        {
            AI.update();
        }
        //操控行为更新
        if (Steerings != null)
        {
            Steerings.update();
        }
    }
예제 #2
0
        public override void Action()
        {
            LeaderAgent leader           = (LeaderAgent)agent.Group.Leader;
            Vector3     SlotInWorldSpace = leader.transform.TransformPoint(leader.FormationSlots[agent.Parameters.ID - 1]);

            //agent.ApplySteerings(SlotInWorldSpace);
            agent.RefRigidbody.AddForce(Steerings.Arrive(agent, SlotInWorldSpace));
            agent.RefRigidbody.MoveRotation(leader.transform.rotation);
        }
예제 #3
0
        public override void ApplySteerings(Vector3 Target)
        {
            Target = new Vector3(Target.x, transform.position.y, Target.z);
            Vector3 force = Steerings.Arrive(this, Target);

            RefRigidbody.AddForce(force);
            if ((Target - transform.position).magnitude > 3)
            {
                RefRigidbody.MoveRotation(Quaternion.LookRotation(Target - transform.position));
            }
        }
예제 #4
0
        public Game()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferWidth  = bounds.Width;
            graphics.PreferredBackBufferHeight = bounds.Height;

            r = new Random();

            deerManager = new DeerManager(this);

            Steerings.InitializeSteering();
        }
예제 #5
0
    public virtual void ApplySteerings(Vector3 Target)
    {
        Vector3 total = new Vector3();

        FindNeighbors();
        total += Steerings.Separation(this) * Parameters.SeparationFactor;
        total += Steerings.Alignment(this) * Parameters.AlignmentFactor;
        total += Steerings.Cohesion(this) * Parameters.CohesionFactor;
        total += Steerings.Seek(this, Target) * Parameters.SeekLeaderFactor;
        total += Steerings.Flee(this, Target) * Parameters.FleeLeaderFactor;

        if (total != Vector3.zero)
        {
            RefRigidbody.AddForce(total);
        }
        if (total != Vector3.zero)
        {
            RefRigidbody.MoveRotation(Quaternion.LookRotation(total));
        }
    }
예제 #6
0
 //物理更新
 public virtual void fixedUpdate()
 {
     AI.fixedUpdate();
     Steerings.fixedUpdate();
 }
예제 #7
0
    protected void CalculateForces()
    {
        if (!CanMove || MaxForce == 0 || MaxSpeed == 0)
        {
            return;
        }
        Profiler.BeginSample("Calculating vehicle forces");

        var force = Vector3.zero;

        Profiler.BeginSample("Adding up basic steerings");
        foreach (var s in Steerings.Where(s => s.enabled))
        {
            force += s.WeighedForce;
        }
        Profiler.EndSample();

        var elapsedTime = Time.time - LastTickTime;

        LastTickTime = Time.time;
        if (IsPlanar)
        {
            force.y = 0;
        }
        LastRawForce = force;

        // enforce limit on magnitude of steering force
        Vector3 clippedForce = Vector3.ClampMagnitude(force, MaxForce);

        // compute acceleration and velocity
        Vector3 newAcceleration = (clippedForce / Mass);

        if (newAcceleration.sqrMagnitude == 0)
        {
            ZeroVelocity();
            DesiredVelocity = Vector3.zero;
        }

        /*
         *      Damp out abrupt changes and oscillations in steering acceleration
         *      (rate is proportional to time step, then clipped into useful range)
         *
         *      The lower the smoothRate parameter, the more noise there is
         *      likely to be in the movement.
         */

        if (_accelerationSmoothRate > 0)
        {
            _smoothedAcceleration = OpenSteerUtility.blendIntoAccumulator(_accelerationSmoothRate,
                                                                          newAcceleration,
                                                                          _smoothedAcceleration);
        }
        else
        {
            _smoothedAcceleration = newAcceleration;
        }

        // Euler integrate (per call time) acceleration into velocity
        var newVelocity = Velocity + _smoothedAcceleration * elapsedTime;

        // Enforce speed limit
        newVelocity     = Vector3.ClampMagnitude(newAcceleration, MaxSpeed);
        DesiredVelocity = newVelocity;

        // Adjusts the velocity by applying the post-processing behaviors.
        //
        // This currently is not also considering the maximum force, nor
        // blending the new velocity into an accumulator. We *could* do that,
        // but things are working just fine for now, and it seems like
        // overkill.
        Vector3 adjustedVelocity = Vector3.zero;

        Profiler.BeginSample("Adding up post-processing steerings");
        foreach (var s in SteeringPostprocessors.Where(s => s.enabled))
        {
            adjustedVelocity += s.WeighedForce;
        }
        Profiler.EndSample();
        if (adjustedVelocity != Vector3.zero)
        {
            adjustedVelocity = Vector3.ClampMagnitude(adjustedVelocity, MaxSpeed);
            TraceDisplacement(adjustedVelocity, Color.cyan);
            TraceDisplacement(newVelocity, Color.white);
            newVelocity = adjustedVelocity;
        }

        // Update vehicle velocity
        RecordCalculatedVelocity(newVelocity);
        Profiler.EndSample();
    }