Exemplo n.º 1
0
    public override void _PhysicsProcess(float delta)
    {
        if (AI == null)
        {
            return;
        }
        AI();

        //move
        if (WayPoint == null)
        {
            MoveCharacter(delta, new Vector3());
            return;
        }

        //rotate
        RotateObjectLocal(Vector3.Up, Mathf.Pi);
        var rot = GlobalTransform.LookingAt(EnemyBody.GlobalTransform.origin, new Vector3(0, 1, 0)).basis.GetEuler();

        if (Mathf.Abs(Transform.basis.GetEuler().y - rot.y) > Mathf.Pi)
        {
            if (rot.y < 0)
            {
                rot.y += 2 * Mathf.Pi;
            }
            else
            {
                rot.y -= 2 * Mathf.Pi;
            }
        }

        rot   = Rotation.LinearInterpolate(rot, delta * RotateSpeed) - Transform.basis.GetEuler();
        rot.y = Mathf.Clamp(rot.y, -1, 1);
        RotateObjectLocal(Vector3.Up, rot.y);
        RotateObjectLocal(Vector3.Up, Mathf.Pi);

        //movement
        var dist = WayPoint.GlobalTransform.origin - GlobalTransform.origin;

        if (Mathf.Sqrt(Mathf.Pow(dist.x, 2) + Mathf.Pow(dist.z, 2)) < Resources.WaypointDistance)
        {
            MoveCharacter(delta, new Vector3());
            return;
        }
        var movement = new Vector3(Mathf.Clamp(dist.x, -1, 1), 0, Mathf.Clamp(dist.z, -1, 1));

        MoveCharacter(delta, movement);

        //makes sure everything is unchanged
        Orthonormalize();

        AnimTree.Advance(delta);
    }
Exemplo n.º 2
0
 protected override void ProcessFrames(float delta) => AnimationTree.Advance(delta);