Beispiel #1
0
    public override void _PhysicsProcess(float delta)
    {
        //implement fsm

        //pathfinding logic
        _points = new List <Vector3>(_nav.GetSimplePath(GlobalTransform.origin, _targetPlayer.GlobalTransform.origin));

        if (_points.Count > 0)
        {
            if (RoundVector(GlobalTransform.origin).x == RoundVector(_points[0]).x&& RoundVector(GlobalTransform.origin).z == RoundVector(_points[0]).z)
            {
                _points.RemoveAt(0);
            }
            Velocity = Translation.DirectionTo(_points[0]) * Speed;
            Velocity = MoveAndSlide(Velocity);
        }

        //Collision Logic

        _rayCast.CastTo = _rayCast.ToLocal(_targetPlayer.GlobalTransform.origin);
        if (_rayCast.IsColliding())
        {
            Spatial collider = (Spatial)_rayCast.GetCollider();
            if (collider is Player && GlobalTransform.origin.DistanceTo(collider.GlobalTransform.origin) <= 3f)
            {
                // GD.Print("hit player");
                GetTree().ChangeScene("res://GameOver/GameOver.tscn");
            }
        }
    }