Пример #1
0
    protected override void EntityUpdate()
    {
        Vector2 force = steer.Calculate();

        //Debug.Log("操纵力是"+force);
        acceleration = force / mass;

        velocity += acceleration;

        velocity = Vector2.ClampMagnitude(velocity, maxSpeed);



        if (velocity.sqrMagnitude > 0.01f)
        {
            //当速度大于某个值的时候进行转向
            if (isUpdateOrientation)
            {
                orientationTarget = velocity;
            }
            UpdateOrientation();
        }


        //TODO 注意引用或值传递
        //print(velocity);
        //velocity.z = -8;
        Pos = Pos + velocity * Time.fixedDeltaTime;
        this.transform.position = new Vector3(Pos.x, Pos.y, -8);
    }
    public IEnumerator Updating()
    {
        while (true)
        {
            Vector2 steeringForce = pSteering.Calculate();
            // just for inspecter view and gizmos
            desiredVelocity = steeringForce;
            Vector2 acceleration = steeringForce / mass;

            // Renewal the speed;
            v_velocity += acceleration * 0.5f;
            Truncate(maxSpeed);
            _pos += v_velocity * 0.5f;
            transform.position = _pos;
            if (LengthSq() > 0.0000001f)
            {
                v_heading = v_velocity.normalized;
                v_side    = Vector2.Perpendicular(v_heading);
            }
            yield return(new WaitForSeconds(0.5f));
        }
    }